#include <dmlite/cpp/catalog.h>
#include <dmlite/cpp/poolmanager.h>
+#include "walk.h"
+
#define DMLITE_CONFIG_DEFAULT "/etc/dmlite.conf"
-void walk(dmlite::Catalog *catalog, const char *path) throw(dmlite::DmException);
-
-
-
static void usage(const char *prg) {
- printf("Usage: %s [OPTIONS] DIRECTORY\n\n", prg);
+ printf("Usage: %s [OPTIONS] DIRECTORY [TARGET]\n\n", prg);
printf("OPTIONS are:\n");
printf(" -h,--help ...... usage information\n");
printf(" -a,--address ... host address (for credentials) [%s]\n", ADDRESS_DEFAULT);
- printf(" -c,--config .... dmlite config file [/etc/dmlite.conf,~/.dmlite.conf]\n");
+ printf(" -c,--config .... dmlite config file [/etc/dmlite.conf]\n");
printf(" -u,--user ...... user name (for credentials) [%s]\n", USER_DEFAULT);
printf("DIRECTORY ........ path to browse and import\n");
+ printf("TARGET... ........ target directory in the catalog [=DIRECTORY]\n");
}
dmlite::Catalog* catalog = NULL;
//dmlite::PoolManager* poolManager = NULL;
dmlite::SecurityCredentials creds;
- char *dmlite_config = NULL, *user = NULL, *address = NULL;
+ char *dmlite_config = NULL, *user = NULL, *address = NULL, *path, *target;
int opt;
bool safetyCheck = true;
// now we can walk safely
try {
- walk(catalog, argv[optind]);
+ path = argv[optind];
+ target = (optind + 1 < argc) ? argv[optind + 1] : path;
+ walk(catalog, path, target);
} catch (dmlite::DmException& e) {
std::cout << "Could not walk." << std::endl
<< "Reason: " << e.what() << std::endl;
#include <dmlite/cpp/dmlite.h>
#include <dmlite/cpp/catalog.h>
+#include "walk.h"
static dmlite::Catalog *catalog;
-static const char *prefix;
+static std::string localPrefix;
+static std::string nsPrefix;
static struct utimbuf utimbuf;
static struct dirent *entry;
static std::string lpath;
time_t diratime, dirmtime;
DIR *dir = NULL;
- lpath = std::string(prefix) + path;
+ lpath = localPrefix + path;
-//printf("[level %d] '%s'/'%s'\n", level, prefix, path);
+//printf("[level %d] '%s'/'%s'\n", level, localPrefix.c_str(), path);
wrapCall(lstat(lpath.c_str(), &pathstat), "can't lstat() '" + lpath + "'");
if (S_ISREG(pathstat.st_mode)) {
- catalog->create(path, pathstat.st_mode);
+ catalog->create(nsPrefix + path, pathstat.st_mode);
utimbuf.actime = pathstat.st_atime;
utimbuf.modtime = pathstat.st_mtime;
- catalog->utime(path, &utimbuf);
+ catalog->utime(nsPrefix + path, &utimbuf);
//catalog->setSize(path, stat.st_size);
} else if (S_ISDIR(pathstat.st_mode)) {
// create under permissive modes
- if (path[0]) catalog->makeDir(path, 0775);
+ if (path[0]) catalog->makeDir(nsPrefix + path, 0775);
// remember for later
dirmode = pathstat.st_mode;
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, prefix, path);
+ 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());
level--;
closedir(dir);
-//printf("[level %d] finalize '%s'/'%s'\n", level, prefix, path);
+//printf("[level %d] finalize '%s'/'%s'\n", level, localPrefix.c_str(), path);
// set remebered values
if (path[0]) {
utimbuf.actime = diratime;
utimbuf.modtime = dirmtime;
- catalog->utime(path, &utimbuf);
- catalog->setMode(path, dirmode);
+ catalog->utime(nsPrefix + path, &utimbuf);
+ catalog->setMode(nsPrefix + path, dirmode);
}
}
}
-void walk(dmlite::Catalog *acatalog, const char *path) throw(dmlite::DmException) {
- prefix = path;
+void walk(dmlite::Catalog *acatalog, const char *path, const char *target) throw(dmlite::DmException) {
+ localPrefix = path;
+ nsPrefix = target;
+ if (nsPrefix == "/") nsPrefix = "";
level = 0;
catalog = acatalog;
acatalog->changeDir("/");