Support symlinks.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Sun, 13 Oct 2013 21:26:33 +0000 (23:26 +0200)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Sun, 13 Oct 2013 21:45:13 +0000 (23:45 +0200)
walk.cpp

index 293a154..8055a56 100644 (file)
--- a/walk.cpp
+++ b/walk.cpp
@@ -19,6 +19,8 @@ static struct dirent *entry;
 static std::string lpath;
 static struct stat pathstat;
 int level;
+char buffer[PATH_MAX];
+char *lnk;
 
 
 static void wrapCall(int retval, std::string msg) throw(dmlite::DmException) {
@@ -80,6 +82,21 @@ static void walk_recursive(const char *path) throw(dmlite::DmException) {
                        catalog->utime(nsPrefix + path, &utimbuf);
                        catalog->setMode(nsPrefix + path, dirmode);
                }
+       } else if (S_ISLNK(pathstat.st_mode)) {
+               memset(buffer, 0, sizeof buffer);
+               wrapCall(readlink(lpath.c_str(), buffer, sizeof(buffer) - 1), "could not read symlink '" + lpath + "'");
+               if (strncmp(buffer, localPrefix.c_str(), localPrefix.size()) == 0) {
+                       lnk = buffer + localPrefix.size();
+                       catalog->symlink(nsPrefix + lnk, nsPrefix + path);
+               } else {
+                       lnk = buffer;
+                       catalog->symlink(lnk, nsPrefix + path);
+               }
+               // XXX: plugin shouldn't follow symlinks probably???
+               //utimbuf.actime = pathstat.st_atime;
+               //utimbuf.modtime = pathstat.st_mtime;
+               //catalog->utime(nsPrefix + path, &utimbuf);
+               //catalog->setMode(nsPrefix + path, pathstat.st_mode);
        }
 }