aboutsummaryrefslogtreecommitdiff
path: root/tests/mventry/driver.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-03-09 02:24:54 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-03-14 17:13:45 +0300
commit8b5e3e0a8f9ec8852cf2f15dab53bfa4436bea87 (patch)
tree0d897762dd01bb956457450668eb2e65b5d89628 /tests/mventry/driver.cxx
parent143d487b5146b2f4f6c33ab56bab7d391f8ac456 (diff)
Add mventry(), mvfile() and mvdir()
Diffstat (limited to 'tests/mventry/driver.cxx')
-rw-r--r--tests/mventry/driver.cxx49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/mventry/driver.cxx b/tests/mventry/driver.cxx
new file mode 100644
index 0000000..cf6099c
--- /dev/null
+++ b/tests/mventry/driver.cxx
@@ -0,0 +1,49 @@
+// file : tests/mventry/driver.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <iostream>
+#include <system_error>
+
+#include <butl/path>
+#include <butl/utility> // operator<<(ostream, exception)
+#include <butl/filesystem>
+
+using namespace std;
+using namespace butl;
+
+// Usage: argv[0] <old-path> <new-path>
+//
+// Rename a file, directory or symlink or move it to the specified directory.
+// For the later case the destination path must have a trailing directory
+// separator. If succeed then exits with the zero code, otherwise prints the
+// error descriptions and exits with the one code.
+//
+int
+main (int argc, const char* argv[])
+try
+{
+ assert (argc == 3);
+
+ path from (argv[1]);
+ path to (argv[2]);
+
+ cpflags fl (cpflags::overwrite_permissions | cpflags::overwrite_content);
+
+ if (to.to_directory ())
+ mventry_into (from, path_cast<dir_path> (move (to)), fl);
+ else
+ mventry (from, to, fl);
+
+ return 0;
+}
+catch (const invalid_path& e)
+{
+ cerr << e << ": " << e.path << endl;
+ return 1;
+}
+catch (const system_error& e)
+{
+ cerr << e << endl;
+ return 1;
+}