diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-06-18 14:41:45 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-06-18 14:41:45 +0200 |
commit | 63e7a4a77cb8ceed7b42561fe3202b0b48d86db6 (patch) | |
tree | bde5a79522225f32ec188ba46d0834486c30f00f /build/filesystem.cxx | |
parent | 28c82c861e38fe05a25e916563e0551ed8fce91e (diff) |
Move path and filesystem from build2 to libbutl
Diffstat (limited to 'build/filesystem.cxx')
-rw-r--r-- | build/filesystem.cxx | 101 |
1 files changed, 0 insertions, 101 deletions
diff --git a/build/filesystem.cxx b/build/filesystem.cxx deleted file mode 100644 index 6485f34..0000000 --- a/build/filesystem.cxx +++ /dev/null @@ -1,101 +0,0 @@ -// file : build/filesystem.cxx -*- C++ -*- -// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#include <build/filesystem> - -#include <unistd.h> // rmdir(), unlink() -#include <sys/types.h> // stat -#include <sys/stat.h> // stat, lstat(), S_IS*, mkdir() - -#include <system_error> - -using namespace std; - -namespace build -{ - bool - dir_exists (const path& p) - { - struct stat s; - if (::lstat (p.string ().c_str (), &s) != 0) - { - if (errno == ENOENT || errno == ENOTDIR) - return false; - else - throw system_error (errno, system_category ()); - } - - return S_ISDIR (s.st_mode); - } - - bool - file_exists (const path& p) - { - struct stat s; - if (::lstat (p.string ().c_str (), &s) != 0) - { - if (errno == ENOENT || errno == ENOTDIR) - return false; - else - throw system_error (errno, system_category ()); - } - - return S_ISREG (s.st_mode); - } - - mkdir_status - try_mkdir (const path& p, mode_t m) - { - mkdir_status r (mkdir_status::success); - - if (::mkdir (p.string ().c_str (), m) != 0) - { - int e (errno); - - // EEXIST means the path already exists but not necessarily as - // a directory. - // - if (e == EEXIST && dir_exists (p)) - return mkdir_status::already_exists; - else - throw system_error (e, system_category ()); - } - - return r; - } - - rmdir_status - try_rmdir (const path& p) - { - rmdir_status r (rmdir_status::success); - - if (::rmdir (p.string ().c_str ()) != 0) - { - if (errno == ENOENT) - r = rmdir_status::not_exist; - else if (errno == ENOTEMPTY || errno == EEXIST) - r = rmdir_status::not_empty; - else - throw system_error (errno, system_category ()); - } - - return r; - } - - rmfile_status - try_rmfile (const path& p) - { - rmfile_status r (rmfile_status::success); - - if (::unlink (p.string ().c_str ()) != 0) - { - if (errno == ENOENT || errno == ENOTDIR) - r = rmfile_status::not_exist; - else - throw system_error (errno, system_category ()); - } - - return r; - } -} |