From 1c36adab776a900adc7325f412b1c8dd61b1a346 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 7 Mar 2018 15:22:51 +0200 Subject: Setup compilation, command line handling --- bdep/utility.cxx | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 bdep/utility.cxx (limited to 'bdep/utility.cxx') 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 + +#include // cout, cin + +#include +#include + +#include + +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; +} -- cgit v1.1