From 08903414e3546bc2c76bef73b2337ccf79886530 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 18 Jun 2015 14:41:44 +0200 Subject: Move path and filesystem from build2 to libbutl --- butl/filesystem | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 butl/filesystem (limited to 'butl/filesystem') diff --git a/butl/filesystem b/butl/filesystem new file mode 100644 index 0000000..10f61f2 --- /dev/null +++ b/butl/filesystem @@ -0,0 +1,61 @@ +// file : butl/filesystem -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BUTL_FILESYSTEM +#define BUTL_FILESYSTEM + +#include // mode_t + +#include + +namespace butl +{ + // Return true if the path is to an existing directory. Note that + // this function resolves symlinks. + // + bool + dir_exists (const path&); + + // Return true if the path is to an existing regular file. Note that + // this function resolves symlinks. + // + bool + file_exists (const path&); + + // Try to create a directory unless it already exists. If you expect + // the directory to exist and performance is important, then you + // should first call dir_exists() above since that's what this + // implementation will do to make sure the path is actually a + // directory. + // + // You should also probably use the default mode 0777 and let the + // umask mechanism adjust it to the user's preferences. + // + // Errors are reported by throwing std::system_error. + // + enum class mkdir_status {success, already_exists}; + + mkdir_status + try_mkdir (const path&, mode_t = 0777); + + // Try to remove the directory returning not_exist if it does not + // exist and not_empty if it is not empty. All other errors are + // reported by throwing std::system_error. + // + enum class rmdir_status {success, not_exist, not_empty}; + + rmdir_status + try_rmdir (const path&); + + // Try to remove the file (or symbolic link) returning not_exist if + // it does not exist. All other errors are reported by throwing + // std::system_error. + // + enum class rmfile_status {success, not_exist}; + + rmfile_status + try_rmfile (const path&); +} + +#endif // BUTL_FILESYSTEM -- cgit v1.1