Skip to content

Commit

Permalink
[llvm][Support][Windows] Fix slash in path for remove_directories (ll…
Browse files Browse the repository at this point in the history
…vm#121448)

Before 925471e remove_directories
supports path with slash (instead of backslash).
The ILCreateFromPathW in new implementation requires backslash path,
so the call to remove_directories will fail if the path contains slash.

This is to normalize the path to make sure remove_directories still
support path with slash as well.
  • Loading branch information
jsji authored Jan 2, 2025
1 parent 1849244 commit 5de7af4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion llvm/lib/Support/Windows/Path.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1373,9 +1373,11 @@ std::error_code closeFile(file_t &F) {
}

std::error_code remove_directories(const Twine &path, bool IgnoreErrors) {
SmallString<128> NativePath;
llvm::sys::path::native(path, NativePath, path::Style::windows_backslash);
// Convert to utf-16.
SmallVector<wchar_t, 128> Path16;
std::error_code EC = widenPath(path, Path16);
std::error_code EC = widenPath(NativePath, Path16);
if (EC && !IgnoreErrors)
return EC;

Expand Down
3 changes: 3 additions & 0 deletions llvm/unittests/Support/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,9 @@ TEST_F(FileSystemTest, Remove) {

ASSERT_NO_ERROR(fs::remove_directories("D:/footest"));

ASSERT_NO_ERROR(fs::remove_directories(Twine(BaseDir) + "/foo/bar/baz"));
ASSERT_FALSE(fs::exists(Twine(BaseDir) + "/foo/bar/baz"));

ASSERT_NO_ERROR(fs::remove_directories(BaseDir));
ASSERT_FALSE(fs::exists(BaseDir));
}
Expand Down

0 comments on commit 5de7af4

Please sign in to comment.