aboutsummaryrefslogtreecommitdiff
path: root/libbuild2
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-08-17 12:04:33 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-08-17 12:04:33 +0200
commit5521a0edd9a2ba8429f7d2e48f754c9d6f66cc3b (patch)
treeec1922b3c804fbd472b8cc977f332ad0f5a4355a /libbuild2
parent534ca7619a62a74bce8e4b30931aaf99f9c3beb6 (diff)
Add mvfile() filesystem utility function
Diffstat (limited to 'libbuild2')
-rw-r--r--libbuild2/filesystem.cxx21
-rw-r--r--libbuild2/filesystem.hxx5
-rw-r--r--libbuild2/version/init.cxx26
3 files changed, 33 insertions, 19 deletions
diff --git a/libbuild2/filesystem.cxx b/libbuild2/filesystem.cxx
index 259de26..0072408 100644
--- a/libbuild2/filesystem.cxx
+++ b/libbuild2/filesystem.cxx
@@ -102,6 +102,27 @@ namespace build2
return ms;
}
+ void
+ mvfile (const path& f, const path& t, uint16_t v)
+ {
+ if (verb >= v)
+ text << "mv " << f << ' ' << t;
+
+ try
+ {
+ butl::mvfile (f, t, (cpflags::overwrite_content |
+ cpflags::overwrite_permissions));
+ }
+ catch (const io_error& e)
+ {
+ fail << "unable to overwrite " << t << " with " << f << ": " << e;
+ }
+ catch (const system_error& e) // EACCES, etc.
+ {
+ fail << "unable to move " << f << " to " << t << ": " << e;
+ }
+ }
+
fs_status<rmfile_status>
rmsymlink (context& ctx, const path& p, bool d, uint16_t v)
{
diff --git a/libbuild2/filesystem.hxx b/libbuild2/filesystem.hxx
index aedfed2..5d26524 100644
--- a/libbuild2/filesystem.hxx
+++ b/libbuild2/filesystem.hxx
@@ -78,6 +78,11 @@ namespace build2
LIBBUILD2_SYMEXPORT fs_status<mkdir_status>
mkdir_p (const dir_path&, uint16_t verbosity = 1);
+ // Rename a file (or file symlink) overwriting the destination if exists.
+ //
+ void
+ mvfile (const path& from, const path& to, uint16_t verbosity = 1);
+
// Remove the file (unless dry-run) and print the standard diagnostics
// starting from the specified verbosity level. The second argument is only
// used in diagnostics, to print the target name. Passing the path for
diff --git a/libbuild2/version/init.cxx b/libbuild2/version/init.cxx
index 7cb5a48..43b6b92 100644
--- a/libbuild2/version/init.cxx
+++ b/libbuild2/version/init.cxx
@@ -370,25 +370,13 @@ namespace build2
// The plan is simple: fixing up the version in a temporary file then
// move it to the original.
//
- try
- {
- auto_rmfile t (fixup_manifest (rs.ctx,
- f,
- path::temp_path ("manifest"),
- m.version));
-
- mvfile (t.path, f, (cpflags::overwrite_content |
- cpflags::overwrite_permissions));
- t.cancel ();
- }
- catch (const io_error& e)
- {
- fail << "unable to overwrite " << f << ": " << e;
- }
- catch (const system_error& e) // EACCES, etc.
- {
- fail << "unable to overwrite " << f << ": " << e;
- }
+ auto_rmfile t (fixup_manifest (rs.ctx,
+ f,
+ path::temp_path ("manifest"),
+ m.version));
+
+ mvfile (t.path, f, verb_never);
+ t.cancel ();
}
static const module_functions mod_functions[] =