-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[Support] Report EISDIR when opening a directory #79880
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
Changes from 7 commits
066a8ca
267039f
76670d2
fe7209d
cdb8623
37a2b46
6b36693
b667596
7b3bc49
166a504
07bcca1
f77a474
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -1296,6 +1296,36 @@ TEST_F(FileSystemTest, UTF8ToUTF16DirectoryIteration) { | |||||||
} | ||||||||
#endif | ||||||||
|
||||||||
#ifndef _WIN32 | ||||||||
TEST_F(FileSystemTest, OpenDirectoryAsFileForRead) { | ||||||||
ASSERT_NO_ERROR(fs::create_directory(Twine(TestDirectory))); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code here does not include code to remove this directory. Perhaps it should? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of llvm-project/llvm/unittests/Support/Path.cpp Lines 665 to 667 in b667596
It seems that It seems we don't need to create/remove a directory here? |
||||||||
ASSERT_EQ(fs::create_directory(Twine(TestDirectory), false), | ||||||||
errc::file_exists); | ||||||||
|
||||||||
std::string Buf(5, '?'); | ||||||||
Expected<fs::file_t> FD = fs::openNativeFileForRead(TestDirectory); | ||||||||
ASSERT_NO_ERROR(errorToErrorCode(FD.takeError())); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test fails on Windows here, because on Windows even attempting to opene the directory for read fails, so the Side note: To fix this on Windows simply replace the |
||||||||
auto Close = make_scope_exit([&] { fs::closeFile(*FD); }); | ||||||||
Expected<size_t> BytesRead = | ||||||||
fs::readNativeFile(*FD, MutableArrayRef(&*Buf.begin(), Buf.size())); | ||||||||
ASSERT_EQ(errorToErrorCode(BytesRead.takeError()), errc::is_a_directory); | ||||||||
} | ||||||||
#endif | ||||||||
|
||||||||
TEST_F(FileSystemTest, OpenDirectoryAsFileForWrite) { | ||||||||
ASSERT_NO_ERROR(fs::create_directory(Twine(TestDirectory))); | ||||||||
ASSERT_EQ(fs::create_directory(Twine(TestDirectory), false), | ||||||||
errc::file_exists); | ||||||||
|
||||||||
int FD; | ||||||||
std::error_code EC; | ||||||||
EC = fs::openFileForWrite(Twine(TestDirectory), FD); | ||||||||
azhan92 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
ASSERT_EQ(EC, errc::is_a_directory); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Same goes for your other test too. |
||||||||
|
||||||||
ASSERT_NO_ERROR(fs::remove_directories(Twine(TestDirectory))); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is better to use |
||||||||
::close(FD); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test crashes on Windows, because you're attempting to close a file handle that hasn't been opened (more precisely, |
||||||||
} | ||||||||
|
||||||||
TEST_F(FileSystemTest, Remove) { | ||||||||
SmallString<64> BaseDir; | ||||||||
SmallString<64> Paths[4]; | ||||||||
|
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.
Nit: looking at other tests in this file, I believe these two would be better grouped in the file with other tests that attempt to open files for read/write. WDYT?
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.
Sure, which other file would you suggest?
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.
@azhan92, I think the idea is to leave the tests in this file but to move them within the file to be adjacent with tests that open files for read/write.