From aeaffec7857301a6d20d7901041918484666d567 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 18 Jun 2003 14:34:03 +0000 Subject: * Dump symlinks. --- src/hash.cc | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/hash.cc b/src/hash.cc index 37f6104fb..fa016c835 100644 --- a/src/hash.cc +++ b/src/hash.cc @@ -192,7 +192,7 @@ static void dumpContents(const string & path, unsigned int size, int fd = open(path.c_str(), O_RDONLY); if (!fd) throw SysError("opening file " + path); - unsigned char buf[16384]; + unsigned char buf[65536]; unsigned int total = 0; ssize_t n; @@ -213,8 +213,6 @@ static void dumpContents(const string & path, unsigned int size, void dumpPath(const string & path, DumpSink & sink) { - cerr << path << endl; - struct stat st; if (lstat(path.c_str(), &st)) throw SysError("getting attributes of path " + path); @@ -225,11 +223,25 @@ void dumpPath(const string & path, DumpSink & sink) writeString("type", sink); writeString("regular", sink); dumpContents(path, st.st_size, sink); - } else if (S_ISDIR(st.st_mode)) { + } + + else if (S_ISDIR(st.st_mode)) { writeString("type", sink); writeString("directory", sink); dumpEntries(path, sink); - } else throw Error("unknown file type: " + path); + } + + else if (S_ISLNK(st.st_mode)) { + writeString("type", sink); + writeString("symlink", sink); + char buf[st.st_size]; + if (readlink(path.c_str(), buf, st.st_size) != st.st_size) + throw SysError("reading symbolic link " + path); + writeString("target", sink); + writeString(string(buf, st.st_size), sink); + } + + else throw Error("unknown file type: " + path); writeString(")", sink); } -- cgit v1.2.3