#include <unistd.h>
#include <utime.h>
-//#include <cstdio>
+#include <cstdio>
#include <dmlite/cpp/dmlite.h>
#include <dmlite/cpp/catalog.h>
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));
}
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;
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
}
} 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);