[PATCH] D45178: Fixes errors with FS iterators caused by https://reviews.llvm.org/D44960
Max Moroz via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 4 12:52:22 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rC329223: Fixes errors with FS iterators caused by https://reviews.llvm.org/D44960 (authored by Dor1s, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D45178?vs=141026&id=141027#toc
Repository:
rC Clang
https://reviews.llvm.org/D45178
Files:
lib/Basic/VirtualFileSystem.cpp
unittests/Basic/VirtualFileSystemTest.cpp
Index: unittests/Basic/VirtualFileSystemTest.cpp
===================================================================
--- unittests/Basic/VirtualFileSystemTest.cpp
+++ unittests/Basic/VirtualFileSystemTest.cpp
@@ -442,16 +442,17 @@
ScopedDir _dd(TestDirectory + "/d/d");
ScopedDir _ddd(TestDirectory + "/d/d/d");
ScopedLink _e("no_such_file", TestDirectory + "/e");
- std::vector<StringRef> Expected = {_b, _bb, _d, _dd, _ddd};
- std::vector<std::string> Contents;
+ std::vector<StringRef> ExpectedBrokenSymlinks = {_a, _ba, _bc, _c, _e};
+ std::vector<StringRef> ExpectedNonBrokenSymlinks = {_b, _bb, _d, _dd, _ddd};
+ std::vector<std::string> VisitedBrokenSymlinks;
+ std::vector<std::string> VisitedNonBrokenSymlinks;
std::error_code EC;
for (vfs::recursive_directory_iterator I(*FS, Twine(TestDirectory), EC), E;
I != E; I.increment(EC)) {
- // Skip broken symlinks.
auto EC2 = std::make_error_code(std::errc::no_such_file_or_directory);
if (EC == EC2) {
- EC.clear();
+ VisitedBrokenSymlinks.push_back(I->getName());
continue;
}
// For bot debugging.
@@ -467,13 +468,20 @@
<< "EC message: " << EC2.message() << "\n";
}
ASSERT_FALSE(EC);
- Contents.push_back(I->getName());
+ VisitedNonBrokenSymlinks.push_back(I->getName());
}
- // Check sorted contents.
- llvm::sort(Contents.begin(), Contents.end());
- EXPECT_EQ(Expected.size(), Contents.size());
- EXPECT_TRUE(std::equal(Contents.begin(), Contents.end(), Expected.begin()));
+ // Check visited file names.
+ std::sort(VisitedBrokenSymlinks.begin(), VisitedBrokenSymlinks.end());
+ std::sort(VisitedNonBrokenSymlinks.begin(), VisitedNonBrokenSymlinks.end());
+ EXPECT_EQ(ExpectedBrokenSymlinks.size(), VisitedBrokenSymlinks.size());
+ EXPECT_TRUE(std::equal(VisitedBrokenSymlinks.begin(),
+ VisitedBrokenSymlinks.end(),
+ ExpectedBrokenSymlinks.begin()));
+ EXPECT_EQ(ExpectedNonBrokenSymlinks.size(), VisitedNonBrokenSymlinks.size());
+ EXPECT_TRUE(std::equal(VisitedNonBrokenSymlinks.begin(),
+ VisitedNonBrokenSymlinks.end(),
+ ExpectedNonBrokenSymlinks.begin()));
}
#endif
Index: lib/Basic/VirtualFileSystem.cpp
===================================================================
--- lib/Basic/VirtualFileSystem.cpp
+++ lib/Basic/VirtualFileSystem.cpp
@@ -286,24 +286,26 @@
public:
RealFSDirIter(const Twine &Path, std::error_code &EC) : Iter(Path, EC) {
- if (!EC && Iter != llvm::sys::fs::directory_iterator()) {
+ if (Iter != llvm::sys::fs::directory_iterator()) {
llvm::sys::fs::file_status S;
- EC = llvm::sys::fs::status(Iter->path(), S, true);
+ std::error_code ErrorCode = llvm::sys::fs::status(Iter->path(), S, true);
CurrentEntry = Status::copyWithNewName(S, Iter->path());
+ if (!EC)
+ EC = ErrorCode;
}
}
std::error_code increment() override {
std::error_code EC;
Iter.increment(EC);
- if (EC) {
- return EC;
- } else if (Iter == llvm::sys::fs::directory_iterator()) {
+ if (Iter == llvm::sys::fs::directory_iterator()) {
CurrentEntry = Status();
} else {
llvm::sys::fs::file_status S;
- EC = llvm::sys::fs::status(Iter->path(), S, true);
+ std::error_code ErrorCode = llvm::sys::fs::status(Iter->path(), S, true);
CurrentEntry = Status::copyWithNewName(S, Iter->path());
+ if (!EC)
+ EC = ErrorCode;
}
return EC;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45178.141027.patch
Type: text/x-patch
Size: 3552 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180404/b500b41d/attachment-0001.bin>
More information about the cfe-commits
mailing list