From a43dac008441cfb7eae9300ba87a8cea943734ce Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Sun, 13 Oct 2013 23:26:33 +0200 Subject: [PATCH] Support symlinks. --- walk.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/walk.cpp b/walk.cpp index 293a154..8055a56 100644 --- 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); } } -- 1.8.2.3