From: František Dvořák Date: Sun, 13 Oct 2013 21:43:53 +0000 (+0200) Subject: More relaxed to local errors (just print and continue). X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=86118c27b85149fa93c68156b6d1826833c25b06;p=dmlite-clients.git More relaxed to local errors (just print and continue). --- diff --git a/walk.cpp b/walk.cpp index 8055a56..a494efd 100644 --- a/walk.cpp +++ b/walk.cpp @@ -4,7 +4,7 @@ #include #include -//#include +#include #include #include @@ -23,13 +23,8 @@ char buffer[PATH_MAX]; char *lnk; -static void wrapCall(int retval, std::string msg) throw(dmlite::DmException) { - if (retval < 0) throw dmlite::DmException(errno, "[level %d] %s: %s", level, msg.c_str(), strerror(errno)); -} - - -static void wrapCall(void *p, std::string msg) throw(dmlite::DmException) { - if (!p) throw dmlite::DmException(errno, "[level %d] %s: %s", level, msg.c_str(), strerror(errno)); +static void error(std::string msg) { + printf("[level %d] %s: %s\n", level, msg.c_str(), strerror(errno)); } @@ -41,7 +36,10 @@ static void walk_recursive(const char *path) throw(dmlite::DmException) { lpath = localPrefix + path; //printf("[level %d] '%s'/'%s'\n", level, localPrefix.c_str(), path); - wrapCall(lstat(lpath.c_str(), &pathstat), "can't lstat() '" + lpath + "'"); + if (lstat(lpath.c_str(), &pathstat) == -1) { + error("can't lstat() '" + lpath + "'"); + return; + } if (S_ISREG(pathstat.st_mode)) { catalog->create(nsPrefix + path, pathstat.st_mode); utimbuf.actime = pathstat.st_atime; @@ -58,21 +56,25 @@ static void walk_recursive(const char *path) throw(dmlite::DmException) { dirmtime = pathstat.st_mtime; // walk! - wrapCall(dir = opendir(lpath.c_str()), "can't open directory '" + lpath + "'"); - level++; - try { - if (level > 10) throw dmlite::DmException(E2BIG, "[level %d] maximul level reached at '%s/%s'", level, localPrefix.c_str(), path); - while ((entry = readdir(dir)) != NULL) { - if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) { - walk_recursive((std::string(path) + "/" + entry->d_name).c_str()); + + if ((dir = opendir(lpath.c_str())) == NULL) { + error("can't open directory '" + lpath + "'"); + } else { + level++; + try { + if (level > 10) throw dmlite::DmException(E2BIG, "[level %d] maximul level reached at '%s/%s'", level, localPrefix.c_str(), path); + while ((entry = readdir(dir)) != NULL) { + if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) { + walk_recursive((std::string(path) + "/" + entry->d_name).c_str()); + } } + } catch (dmlite::DmException& e) { + closedir(dir); + throw; } - } catch (dmlite::DmException& e) { + level--; closedir(dir); - throw; } - level--; - closedir(dir); //printf("[level %d] finalize '%s'/'%s'\n", level, localPrefix.c_str(), path); // set remebered values @@ -84,7 +86,10 @@ static void walk_recursive(const char *path) throw(dmlite::DmException) { } } 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 (readlink(lpath.c_str(), buffer, sizeof(buffer) - 1) == (ssize_t)-1) { + error("could not read symlink '" + lpath + "'"); + return; + } if (strncmp(buffer, localPrefix.c_str(), localPrefix.size()) == 0) { lnk = buffer + localPrefix.size(); catalog->symlink(nsPrefix + lnk, nsPrefix + path);