Skip to content

[llvm][Support][Windows] Fix slash in path for remove_directories #121448

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 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
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: 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"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks; does this particular case fail before this change? (Or would we need to create this particular path first to check that it really is removed?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it was failing without the fix .

Copy link
Member Author

@jsji jsji Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bash-3.2$ ./unittests/Support/SupportTests.exe --gtest_filter=FileSystemTest.Remove
Note: Google Test filter = FileSystemTest.Remove
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from FileSystemTest
[ RUN      ] FileSystemTest.Remove
Test Directory: C:\Users\jinsongj\AppData\Local\Temp\3\file-system-test-09f535
D:/llvm/llvm/unittests/Support/Path.cpp(1339): error: Value of: fs::exists(Twine(BaseDir) + "/foo/bar/baz")
  Actual: true
Expected: false

[  FAILED  ] FileSystemTest.Remove (54 ms)
[----------] 1 test from FileSystemTest (57 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (63 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] FileSystemTest.Remove

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The path was created above in line 1306, we just did not test the removal of it.

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

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