blob: eab2ce3f929758d6df0ca67eabe2c18305d6dc3a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
// file : tests/mventry/driver.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
#include <cassert>
#ifndef __cpp_lib_modules
#include <iostream>
#include <system_error>
#endif
// Other includes.
#ifdef __cpp_modules
#ifdef __cpp_lib_modules
import std.core;
import std.io;
#endif
import butl.path;
import butl.utility; // operator<<(ostream, exception)
import butl.filesystem;
#else
#include <libbutl/path.mxx>
#include <libbutl/utility.mxx>
#include <libbutl/filesystem.mxx>
#endif
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;
}
|