aboutsummaryrefslogtreecommitdiff
path: root/bdep/utility.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-03-07 15:22:51 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-03-07 15:22:51 +0200
commit1c36adab776a900adc7325f412b1c8dd61b1a346 (patch)
tree0227b8c5697d24a862aedd59b9bfe28cc84e91b4 /bdep/utility.cxx
parent2e2c3a81b47c650334f5767ddb4ebb2746ef98f1 (diff)
Setup compilation, command line handling
Diffstat (limited to 'bdep/utility.cxx')
-rw-r--r--bdep/utility.cxx96
1 files changed, 96 insertions, 0 deletions
diff --git a/bdep/utility.cxx b/bdep/utility.cxx
new file mode 100644
index 0000000..cb005a0
--- /dev/null
+++ b/bdep/utility.cxx
@@ -0,0 +1,96 @@
+// file : bdep/utility.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <bdep/utility.hxx>
+
+#include <iostream> // cout, cin
+
+#include <libbutl/process.mxx>
+#include <libbutl/fdstream.mxx>
+
+#include <bdep/diagnostics.hxx>
+
+using namespace std;
+using namespace butl;
+
+namespace bdep
+{
+ const string empty_string;
+ const path empty_path;
+ const dir_path empty_dir_path;
+
+ bool
+ exists (const path& f, bool ignore_error)
+ {
+ try
+ {
+ return file_exists (f, true /* follow_symlinks */, ignore_error);
+ }
+ catch (const system_error& e)
+ {
+ fail << "unable to stat path " << f << ": " << e << endf;
+ }
+ }
+
+ bool
+ exists (const dir_path& d, bool ignore_error)
+ {
+ try
+ {
+ return dir_exists (d, ignore_error);
+ }
+ catch (const system_error& e)
+ {
+ fail << "unable to stat path " << d << ": " << e << endf;
+ }
+ }
+
+ bool
+ empty (const dir_path& d)
+ {
+ try
+ {
+ return dir_empty (d);
+ }
+ catch (const system_error& e)
+ {
+ fail << "unable to scan directory " << d << ": " << e << endf;
+ }
+ }
+
+ void
+ mk (const dir_path& d)
+ {
+ if (verb >= 3)
+ text << "mkdir " << d;
+
+ try
+ {
+ try_mkdir (d);
+ }
+ catch (const system_error& e)
+ {
+ fail << "unable to create directory " << d << ": " << e;
+ }
+ }
+
+ void
+ rm (const path& f, uint16_t v)
+ {
+ if (verb >= v)
+ text << "rm " << f;
+
+ try
+ {
+ if (try_rmfile (f) == rmfile_status::not_exist)
+ fail << "unable to remove file " << f << ": file does not exist";
+ }
+ catch (const system_error& e)
+ {
+ fail << "unable to remove file " << f << ": " << e;
+ }
+ }
+
+ dir_path exec_dir;
+}