From: František Dvořák Date: Sun, 13 Oct 2013 21:26:33 +0000 (+0200) Subject: Support symlinks. X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=a43dac008441cfb7eae9300ba87a8cea943734ce;p=dmlite-clients.git Support symlinks. --- 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); } }