diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2016-07-02 17:21:54 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2016-07-07 17:39:46 +0300 |
commit | 5b1c20f2315cd7fc624ffd31abdcc03b409bfcb2 (patch) | |
tree | c5c7b76dead92292b84586bda1b1256170195c48 /butl/filesystem | |
parent | 15634965e8f0ab753898f5607ba11288556d1235 (diff) |
Add cpfile()
Diffstat (limited to 'butl/filesystem')
-rw-r--r-- | butl/filesystem | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/butl/filesystem b/butl/filesystem index 780779f..7b23fc5 100644 --- a/butl/filesystem +++ b/butl/filesystem @@ -162,6 +162,47 @@ namespace butl mkhardlink (target, link, true); } + // File copy flags. + // + enum class cpflags: std::uint16_t + { + overwrite_content = 0x1, + overwrite_permissions = 0x2, + + none = 0 + }; + + cpflags operator& (cpflags, cpflags); + cpflags operator| (cpflags, cpflags); + cpflags operator&= (cpflags&, cpflags); + cpflags operator|= (cpflags&, cpflags); + + // Copy a regular file, including its permissions. Throw std::system_error + // on failure. Fail if the destination file exists and the overwrite_content + // flag is not set. Leave permissions of an existing destination file intact + // unless the overwrite_permissions flag is set. Delete incomplete copies + // before throwing. + // + // Note that in case of overwriting, the existing destination file gets + // truncated (not deleted) prior to being overwritten. As a side-effect, + // hard link to the destination file will still reference the same file + // system node after the copy. + // + // Also note that if the overwrite_content flag is not set and the + // destination is a dangling symbolic link, then this function will still + // fail. + // + void + cpfile (const path& from, const path& to, cpflags = cpflags::none); + + // Copy a regular file to an existing directory. + // + inline void + cpfile (const path& from, const dir_path& to, cpflags fl = cpflags::none) + { + cpfile (from, to / from.leaf (), fl); + } + // Return timestamp_nonexistent if the entry at the specified path // does not exist or is not a path. All other errors are reported // by throwing std::system_error. Note that this function resolves @@ -196,9 +237,18 @@ namespace butl permissions operator&= (permissions&, permissions); permissions operator|= (permissions&, permissions); + // Get path permissions. Throw std::system_error on failure. Note that this + // function resolves symlinks. + // permissions path_permissions (const path&); + // Set path permissions. Throw std::system_error on failure. Note that this + // function resolves symlinks. + // + void + path_permissions (const path&, permissions); + // Directory entry iteration. // enum class entry_type |