[PATCH] D45178: Fixes errors caused by https://reviews.llvm.org/D44960
Yuke Liao via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 2 12:32:31 PDT 2018
liaoyuke created this revision.
Herald added subscribers: cfe-commits, mgrang.
In https://reviews.llvm.org/D44960, file status check is executed every
time a real file system directory iterator is constructed or
incremented, and emits an error code. This change list fixes the errors
in VirtualFileSystem caused by https://reviews.llvm.org/D44960.
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.
- std::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
@@ -242,25 +242,28 @@
llvm::sys::fs::directory_iterator Iter;
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 error_code = llvm::sys::fs::status(Iter->path(), S, true);
CurrentEntry = Status::copyWithNewName(S, Iter->path());
+ if (!EC)
+ EC = error_code;
}
}
std::error_code increment() override {
std::error_code EC;
Iter.increment(EC);
- if (EC) {
- return EC;
- } else 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);
- CurrentEntry = Status::copyWithNewName(S, Iter->path());
- }
+ if (Iter == llvm::sys::fs::directory_iterator()) {
+ CurrentEntry = Status();
+ } else {
+ llvm::sys::fs::file_status S;
+ std::error_code error_code = llvm::sys::fs::status(Iter->path(), S, true);
+ CurrentEntry = Status::copyWithNewName(S, Iter->path());
+ if (!EC)
+ EC = error_code;
+ }
+
return EC;
}
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45178.140671.patch
Type: text/x-patch
Size: 3747 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180402/94718dc1/attachment-0001.bin>
More information about the cfe-commits
mailing list