Skip to content

On Windows use RemoveDirectoryW to delete empty directory before renaming directory to it #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Database/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ static std::error_code renameDirectory(const Twine &from, const Twine &to) {
if (!llvm::sys::fs::exists(from)) {
return make_error_code(llvm::errc::no_such_file_or_directory);
}
// MoveFileW does not override an existing directory. Remove the destination if it exists.
llvm::sys::fs::remove_directories(to, /*IgnoreErrors=*/true);
SmallVector<wchar_t, 128> wideFrom;
if (std::error_code ec = llvm::sys::path::widenPath(from, wideFrom)) {
return ec;
Expand All @@ -65,6 +63,8 @@ static std::error_code renameDirectory(const Twine &from, const Twine &to) {
if (std::error_code ec = llvm::sys::path::widenPath(to, wideTo)) {
return ec;
}
// MoveFileW does not override an existing directory. Remove the destination if it is an empty directory.
::RemoveDirectoryW(wideTo.begin());
if (!::MoveFileW(wideFrom.begin(), wideTo.begin())) {
return llvm::mapWindowsError(GetLastError());
}
Expand Down