[PATCH] D44960: Prevent llvm-cov from hanging when a symblink doesn't exist.
Yuke Liao via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 27 17:46:26 PDT 2018
liaoyuke updated this revision to Diff 140028.
liaoyuke marked 4 inline comments as done.
liaoyuke added a comment.
Addressed comments and added unit test.
Repository:
rL LLVM
https://reviews.llvm.org/D44960
Files:
include/llvm/Support/FileSystem.h
tools/llvm-cov/CodeCoverage.cpp
unittests/Support/Path.cpp
Index: unittests/Support/Path.cpp
===================================================================
--- unittests/Support/Path.cpp
+++ unittests/Support/Path.cpp
@@ -901,27 +901,17 @@
ASSERT_TRUE(std::equal(visited.begin(), visited.end(), expected.begin()));
visited.clear();
- // The recursive directory iterator has to stat the file, so we need to skip
- // the broken symlinks.
- for (fs::recursive_directory_iterator
- i(Twine(TestDirectory) + "/symlink", ec),
- e;
- i != e; i.increment(ec)) {
- ASSERT_NO_ERROR(ec);
-
- ErrorOr<fs::basic_file_status> status = i->status();
- if (status.getError() ==
- std::make_error_code(std::errc::no_such_file_or_directory)) {
- i.no_push();
- continue;
+ // Iterator throws an error if encouters a broken symlink with follow_symlinks
+ // being true.
+ bool ErrorOccured = false;
+ for (fs::recursive_directory_iterator i(
+ Twine(TestDirectory) + "/symlink", ec), e; i != e; i.increment(ec)) {
+ if (!ec) {
+ ErrorOccured = true;
+ break;
}
-
- visited.push_back(path::filename(i->path()));
}
- std::sort(visited.begin(), visited.end());
- expected = {"b", "bb", "d", "da", "dd", "ddd", "ddd"};
- ASSERT_TRUE(visited.size() == expected.size());
- ASSERT_TRUE(std::equal(visited.begin(), visited.end(), expected.begin()));
+ ASSERT_TRUE(ErrorOccured);
visited.clear();
// This recursive directory iterator doesn't follow symlinks, so we don't need
Index: tools/llvm-cov/CodeCoverage.cpp
===================================================================
--- tools/llvm-cov/CodeCoverage.cpp
+++ tools/llvm-cov/CodeCoverage.cpp
@@ -199,7 +199,7 @@
if (PathRemapping)
addCollectedPath(Path);
else
- error("Missing source file", Path);
+ warning("Source file doesn't exit, proceeded by ignoring it.", Path);
return;
}
@@ -210,13 +210,17 @@
if (llvm::sys::fs::is_directory(Status)) {
std::error_code EC;
+ std::string PathBeforeErrorOccurs;
for (llvm::sys::fs::recursive_directory_iterator F(Path, EC), E;
F != E && !EC; F.increment(EC)) {
+ PathBeforeErrorOccurs = F->path();
if (llvm::sys::fs::is_regular_file(F->path()))
addCollectedPath(F->path());
}
- if (EC)
- warning(EC.message(), Path);
+ if (EC) {
+ warning(EC.message(), PathBeforeErrorOccurs);
+ warning("Code coverage results may be incomplete.");
+ }
}
}
Index: include/llvm/Support/FileSystem.h
===================================================================
--- include/llvm/Support/FileSystem.h
+++ include/llvm/Support/FileSystem.h
@@ -1031,8 +1031,10 @@
State->HasNoPushRequest = false;
else {
ErrorOr<basic_file_status> st = State->Stack.top()->status();
- if (!st) return *this;
- if (is_directory(*st)) {
+ if (!st) {
+ ec = st.getError();
+ return *this;
+ } else if (is_directory(*st)) {
State->Stack.push(directory_iterator(*State->Stack.top(), ec, Follow));
if (ec) return *this;
if (State->Stack.top() != end_itr) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44960.140028.patch
Type: text/x-patch
Size: 3140 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180328/42575100/attachment.bin>
More information about the llvm-commits
mailing list