Skip to content

Commit df0d11a

Browse files
committed
[llvm][Support][Windows] Fix slash in path for remove_directories (#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.
1 parent 12c4b82 commit df0d11a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

llvm/lib/Support/Windows/Path.inc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1373,9 +1373,11 @@ std::error_code closeFile(file_t &F) {
13731373
}
13741374

13751375
std::error_code remove_directories(const Twine &path, bool IgnoreErrors) {
1376+
SmallString<128> NativePath;
1377+
llvm::sys::path::native(path, NativePath, path::Style::windows_backslash);
13761378
// Convert to utf-16.
13771379
SmallVector<wchar_t, 128> Path16;
1378-
std::error_code EC = widenPath(path, Path16);
1380+
std::error_code EC = widenPath(NativePath, Path16);
13791381
if (EC && !IgnoreErrors)
13801382
return EC;
13811383

llvm/unittests/Support/Path.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,9 @@ TEST_F(FileSystemTest, Remove) {
13261326

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

1329+
ASSERT_NO_ERROR(fs::remove_directories(Twine(BaseDir) + "/foo/bar/baz"));
1330+
ASSERT_FALSE(fs::exists(Twine(BaseDir) + "/foo/bar/baz"));
1331+
13291332
ASSERT_NO_ERROR(fs::remove_directories(BaseDir));
13301333
ASSERT_FALSE(fs::exists(BaseDir));
13311334
}

0 commit comments

Comments
 (0)