From 5521a0edd9a2ba8429f7d2e48f754c9d6f66cc3b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 17 Aug 2020 12:04:33 +0200 Subject: Add mvfile() filesystem utility function --- libbuild2/filesystem.cxx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'libbuild2/filesystem.cxx') 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 rmsymlink (context& ctx, const path& p, bool d, uint16_t v) { -- cgit v1.1