diff options
author | Benjamin Barenblat <bbaren@mit.edu> | 2016-02-21 20:19:12 -0500 |
---|---|---|
committer | Benjamin Barenblat <bbaren@mit.edu> | 2016-02-21 20:38:12 -0500 |
commit | 4f9c17ee5044c68a358a92e90772eea5b3966e3c (patch) | |
tree | b98cd677b7ba7b0b7d010ebe0e2797afc74f7d09 /src/posix_extras.cc | |
parent | 90c61f66909affa269dfb396f0e5cc67f4e4de44 (diff) |
Implement rename
Diffstat (limited to 'src/posix_extras.cc')
-rw-r--r-- | src/posix_extras.cc | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/posix_extras.cc b/src/posix_extras.cc index 5fc60f6..17fe275 100644 --- a/src/posix_extras.cc +++ b/src/posix_extras.cc @@ -25,6 +25,7 @@ #include <dirent.h> #include <fcntl.h> #include <glog/logging.h> +#include <stdio.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> @@ -129,6 +130,16 @@ std::vector<std::uint8_t> File::Read(off_t offset, size_t bytes) const { return result; } +void File::RenameAt(const char* old_path, const char* new_path) const { + if (old_path[0] == '/' || new_path[0] == '/') { + throw std::invalid_argument("absolute path"); + } + + if (renameat(fd_, old_path, fd_, new_path) == -1) { + throw SystemError(); + } +} + void File::RmDirAt(const char* const path) const { if (path[0] == '/') { throw std::invalid_argument("absolute path"); |