[llvm] [Support] Report EISDIR when opening a directory (PR #79880)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 16 00:07:31 PDT 2024
================
@@ -1296,6 +1296,29 @@ TEST_F(FileSystemTest, UTF8ToUTF16DirectoryIteration) {
}
#endif
+TEST_F(FileSystemTest, OpenDirectoryAsFileForRead) {
+ std::string Buf(5, '?');
+ Expected<fs::file_t> FD = fs::openNativeFileForRead(TestDirectory);
+#ifdef _WIN32
+ ASSERT_EQ(errorToErrorCode(BytesRead.takeError()), errc::is_a_directory);
+#else
+ ASSERT_THAT_EXPECTED(FD, Succeeded());
+ 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) {
+ int FD;
+ std::error_code EC;
+ EC = fs::openFileForWrite(Twine(TestDirectory), FD);
----------------
jh7370 wrote:
```suggestion
std::error_code EC = fs::openFileForWrite(Twine(TestDirectory), FD);
```
https://github.com/llvm/llvm-project/pull/79880
More information about the llvm-commits
mailing list