From 4f9c17ee5044c68a358a92e90772eea5b3966e3c Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Sun, 21 Feb 2016 20:19:12 -0500 Subject: Implement rename --- src/posix_extras.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/posix_extras.cc') 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 #include #include +#include #include #include #include @@ -129,6 +130,16 @@ std::vector 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"); -- cgit v1.2.3