int main(int argc, char *argv[]) {
dmlite::PluginManager manager;
std::string conf = DMLITE_DEFAULT_CONF;
+ std::string operation;
+ std::string path = "/tmp/pokus";
+ //std::string path = "/dpm/zcu.cz/home/vo.org/pokus/xMaster_Splinters_Door2.jpg";
+ std::string arg;
if (argc < 3) {
std::cout << "Usage: " << argv[0] << " [ DMLITE_CONFIGFILE [ s | d | h | (r|w|c) [PATH] | z [PATH [SIZE]] ] ]" << std::endl;
if (argc < 3) return 0;
- switch (argv[2][0]) {
- case 's':
- try {
- dmlite::ExtendedStat xstat = catalog->extendedStat("pokus");
- std::cout << "Success!" << std::endl;
- }
- catch (dmlite::DmException& e) {
- std::cout << "Could not stat the file." << std::endl
- << "Reason: " << e.what() << std::endl;
- return e.code();
- }
- break;
+ if (argc >= 4) path = argv[3];
+ if (argc >= 5) arg = argv[4];
- case 'd':
+ try {
+ switch (argv[2][0]) {
+ case 's': {
+ dmlite::ExtendedStat xstat;
- try {
- std::string path;
- dmlite::Directory* dir;
+ operation = "stat the file";
- path="/tmp/pokus";
- if (argc >= 4) path = argv[3];
+ xstat = catalog->extendedStat(path);
+ std::cout << "Success!" << std::endl;
+ break;
+ }
+
+ case 'd': {
+ dmlite::Directory* dir;
dmlite::ExtendedStat* xstat;
+ operation = "list the directory";
+
dir = catalog->openDir(path);
std::cout << "Content of the directory " << path << std::endl;
catalog->closeDir(dir);
std::cout << "Success!" << std::endl;
#endif
+ break;
}
- catch (dmlite::DmException& e) {
- std::cout << "Could not open the directory." << std::endl
- << "Reason: " << e.what() << std::endl;
- return e.code();
- }
- break;
- case 'h':
- try {
+ case 'h': {
std::string d;
+ operation = "change the directory";
+
d = catalog->getWorkingDir();
std::cout << "Current directory before: '" << d << "'" << std::endl;
d = catalog->getWorkingDir();
std::cout << "Current directory after: '" << d << "'" << std::endl;
- } catch (dmlite::DmException& e) {
- std::cout << "Error." << std::endl
- << "Reason: " << e.what() << std::endl;
- return e.code();
+
+ break;
}
- break;
- case 'r':
- try {
- std::string path;
+ case 'r': {
dmlite::Location loc;
dmlite::Location::const_iterator i;
unsigned n;
- path = "/tmp/pokus";
- //path = "/dpm/zcu.cz/home/vo.org/pokus/xMaster_Splinters_Door2.jpg";
- if (argc >= 4) path = argv[3];
+ operation = "read";
+
loc = poolManager->whereToRead(path);
for (i = loc.begin(), n = 0; i != loc.end(); i++, n++) {
std::cout << "Chunk " << n << ": " << i->url.toString() << " (" << i->offset << '-' << i->offset + i->size << ")" << std::endl;
}
- } catch (dmlite::DmException& e) {
- std::cout << "Could not read." << std::endl
- << "Reason: " << e.what() << std::endl;
- return e.code();
+
+ break;
}
- break;
- case 'w':
- try {
- std::string path;
+ case 'w': {
dmlite::Location loc;
dmlite::Location::const_iterator i;
unsigned n;
- path = "/tmp/pokus";
- //path = "/dpm/zcu.cz/home/vo.org/pokus/xMaster_Splinters_Door2.jpg";
- if (argc >= 4) path = argv[3];
+ operation = "write";
+
loc = poolManager->whereToWrite(path);
for (i = loc.begin(), n = 0; i != loc.end(); i++, n++) {
std::cout << "Chunk " << n << ": " << i->url.toString() << " (" << i->offset << '-' << i->offset + i->size << ")" << std::endl;
}
- } catch (dmlite::DmException& e) {
- std::cout << "Could not write." << std::endl
- << "Reason: " << e.what() << std::endl;
- return e.code();
+
+ break;
}
- break;
-
- case 'c':
- try {
- std::string path;
-
- path = "/tmp/pokus";
- if (argc >= 4) path = argv[3];
- catalog->create(path, 0644);
- } catch (dmlite::DmException& e) {
- std::cout << "Could not create." << std::endl
- << "Reason: " << e.what() << std::endl;
- return e.code();
+
+ case 'c': {
+ mode_t mode = 0644;
+
+ operation = "create";
+
+ if (argc >= 5) mode = atoll(arg.c_str());
+ catalog->create(path, mode);
+
+ break;
}
- break;
- case 'z':
- try {
- std::string path;
+ case 'z': {
size_t size;
- path = "/tmp/pokus";
+ operation = "set size";
size = 20000;
- if (argc >= 4) path = argv[3];
- if (argc >= 5) size = atoll(argv[4]);
+ if (argc >= 5) size = strtoull(arg.c_str(), NULL, 8);
catalog->setSize(path, size);
- } catch (dmlite::DmException& e) {
- std::cout << "Could not set size." << std::endl
- << "Reason: " << e.what() << std::endl;
- return e.code();
+
+ break;
}
+ }
+ } catch (dmlite::DmException& e) {
+ std::cout << "Could not " << operation << "." << std::endl
+ << "Reason: " << e.what() << std::endl;
+ return e.code();
}
// delete catalog;