-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
Before 925471e remove_directories supports path with slash (instead of backslash). The ILCreateFromPathW in new implementation requirs 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.
@llvm/pr-subscribers-llvm-support Author: Jinsong Ji (jsji) ChangesBefore 925471e remove_directories This is to normalize the path to make sure remove_directories still Full diff: https://github.com/llvm/llvm-project/pull/121448.diff 1 Files Affected:
diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc
index 17db114caeb1ec..5b311e7c475c56 100644
--- a/llvm/lib/Support/Windows/Path.inc
+++ b/llvm/lib/Support/Windows/Path.inc
@@ -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;
|
@llvm/pr-subscribers-platform-windows Author: Jinsong Ji (jsji) ChangesBefore 925471e remove_directories This is to normalize the path to make sure remove_directories still Full diff: https://github.com/llvm/llvm-project/pull/121448.diff 1 Files Affected:
diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc
index 17db114caeb1ec..5b311e7c475c56 100644
--- a/llvm/lib/Support/Windows/Path.inc
+++ b/llvm/lib/Support/Windows/Path.inc
@@ -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;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks.
Do you think it would be feasible to hit this case in one of the unit tests? IIRC the existing unit test already tests a number of tricky corner cases relating to this implementation.
@@ -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")); |
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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 .
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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.