Skip to content

Commit c05c104

Browse files
committed
Implement Filesystem::Rename on Windows
1 parent b5d2cfe commit c05c104

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Firestore/core/src/firebase/firestore/util/filesystem_win.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "Firestore/core/src/firebase/firestore/util/hard_assert.h"
2828
#include "Firestore/core/src/firebase/firestore/util/path.h"
29+
#include "Firestore/core/src/firebase/firestore/util/statusor.h"
2930
#include "Firestore/core/src/firebase/firestore/util/string_format.h"
3031
#include "absl/memory/memory.h"
3132

@@ -148,6 +149,16 @@ Status Filesystem::RemoveFile(const Path& path) {
148149
error, StringFormat("Could not delete file %s", path.ToUtf8String()));
149150
}
150151

152+
Status Filesystem::Rename(const Path& from_path, const Path& to_path) {
153+
if (::MoveFileW(from_path.c_str(), to_path.c_str())) {
154+
return Status::OK();
155+
}
156+
157+
DWORD error = ::GetLastError();
158+
return Status::FromLastError(
159+
error, StringFormat("Could not rename file %s to %s", from_path.ToUtf8String(), to_path.ToUtf8String()));
160+
}
161+
151162
namespace {
152163

153164
class WindowsDirectoryIterator : public DirectoryIterator {

0 commit comments

Comments
 (0)