Check if ParentFileValue is a directory when evaluating a FileFunction node.
RELNOTES: None.
PiperOrigin-RevId: 205288166
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/FileFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/FileFunction.java
index 53b1cec..279f6af 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/FileFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/FileFunction.java
@@ -21,7 +21,6 @@
import com.google.devtools.build.lib.actions.FileStateType;
import com.google.devtools.build.lib.actions.FileStateValue;
import com.google.devtools.build.lib.actions.FileValue;
-import com.google.devtools.build.lib.actions.InconsistentFilesystemException;
import com.google.devtools.build.lib.pkgcache.PathPackageLocator;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.vfs.Path;
@@ -138,7 +137,7 @@
parentRealRootedPath.getRoot(),
parentRealRootedPath.getRootRelativePath().getRelative(baseName));
- if (!parentFileValue.exists()) {
+ if (!parentFileValue.exists() || !parentFileValue.isDirectory()) {
return Pair.<RootedPath, FileStateValue>of(
realRootedPath, FileStateValue.NONEXISTENT_FILE_STATE_NODE);
}
@@ -150,14 +149,6 @@
if (realFileStateValue == null) {
return null;
}
- if (realFileStateValue.getType() != FileStateType.NONEXISTENT
- && parentFileValue != null && !parentFileValue.isDirectory()) {
- String type = realFileStateValue.getType().toString().toLowerCase();
- String message = type + " " + rootedPath.asPath() + " exists but its parent "
- + "path " + parentFileValue.realRootedPath().asPath() + " isn't an existing directory.";
- throw new FileFunctionException(new InconsistentFilesystemException(message),
- Transience.TRANSIENT);
- }
return Pair.of(realRootedPath, realFileStateValue);
}
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java
index 1401bde..65639f3 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java
@@ -898,69 +898,6 @@
}
@Test
- public void testFilesystemInconsistencies_ParentIsntADirectory() throws Exception {
- file("a/b");
- // Our custom filesystem says "a/b" exists but its parent "a" is a file.
- FileStatus inconsistentParentFileStatus =
- new FileStatus() {
- @Override
- public boolean isFile() {
- return true;
- }
-
- @Override
- public boolean isSpecialFile() {
- return false;
- }
-
- @Override
- public boolean isDirectory() {
- return false;
- }
-
- @Override
- public boolean isSymbolicLink() {
- return false;
- }
-
- @Override
- public long getSize() throws IOException {
- return 0;
- }
-
- @Override
- public long getLastModifiedTime() throws IOException {
- return 0;
- }
-
- @Override
- public long getLastChangeTime() throws IOException {
- return 0;
- }
-
- @Override
- public long getNodeId() throws IOException {
- return 0;
- }
- };
- fs.stubStat(path("a"), inconsistentParentFileStatus);
- // Disable fast-path md5 so that we don't try try to md5 the "a" (since it actually physically
- // is a directory).
- fastDigest = false;
- SequentialBuildDriver driver = makeDriver();
- SkyKey skyKey = skyKey("a/b");
- EvaluationResult<FileValue> result =
- driver.evaluate(
- ImmutableList.of(skyKey), false, DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE);
- assertThat(result.hasError()).isTrue();
- ErrorInfo errorInfo = result.getError(skyKey);
- assertThat(errorInfo.getException()).isInstanceOf(InconsistentFilesystemException.class);
- assertThat(errorInfo.getException())
- .hasMessageThat()
- .contains("file /root/a/b exists but its parent path /root/a isn't an existing directory");
- }
-
- @Test
public void testFilesystemInconsistencies_GetFastDigest() throws Exception {
file("a");
// Our custom filesystem says "a/b" exists but "a" does not exist.
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/PackageFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/PackageFunctionTest.java
index 5750221..0dd046d 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/PackageFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/PackageFunctionTest.java
@@ -125,11 +125,11 @@
Path fooBuildFile = scratch.file("foo/BUILD");
Path fooDir = fooBuildFile.getParentDirectory();
- // Our custom filesystem says "foo/BUILD" exists but its parent "foo" is a file.
- FileStatus inconsistentParentFileStatus = new FileStatus() {
+ // Our custom filesystem says that fooDir is neither a file nor directory nor symlink
+ FileStatus inconsistentFileStatus = new FileStatus() {
@Override
public boolean isFile() {
- return true;
+ return false;
}
@Override
@@ -167,13 +167,14 @@
return 0;
}
};
- fs.stubStat(fooDir, inconsistentParentFileStatus);
+
+ fs.stubStat(fooBuildFile, inconsistentFileStatus);
RootedPath pkgRootedPath = RootedPath.toRootedPath(pkgRoot, fooDir);
SkyValue fooDirValue = FileStateValue.create(pkgRootedPath, tsgm);
differencer.inject(ImmutableMap.of(FileStateValue.key(pkgRootedPath), fooDirValue));
SkyKey skyKey = PackageValue.key(PackageIdentifier.parse("@//foo"));
- String expectedMessage = "/workspace/foo/BUILD exists but its parent path /workspace/foo isn't "
- + "an existing directory";
+ String expectedMessage = "according to stat, existing path /workspace/foo/BUILD is neither"
+ + " a file nor directory nor symlink.";
EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate(
getSkyframeExecutor(), skyKey, /*keepGoing=*/false, reporter);
assertThat(result.hasError()).isTrue();
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeLabelVisitorTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeLabelVisitorTest.java
index eb43635..a665d40 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeLabelVisitorTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeLabelVisitorTest.java
@@ -447,13 +447,12 @@
reporter.removeHandler(failFastHandler);
scratch.file("foo/BUILD", "sh_library(name = 'foo', deps = ['//bar:baz/fizz'])");
Path barBuildFile = scratch.file("bar/BUILD", "sh_library(name = 'bar/baz')");
- Path bazDir = barBuildFile.getParentDirectory().getRelative("baz");
scratch.file("bar/baz/BUILD");
- FileStatus inconsistentParentFileStatus =
+ FileStatus inconsistentFileStatus =
new FileStatus() {
@Override
public boolean isFile() {
- return true;
+ return false;
}
@Override
@@ -491,8 +490,8 @@
return 0;
}
};
- fs.stubStat(bazDir, inconsistentParentFileStatus);
- Set<Label> labels = ImmutableSet.of(Label.parseAbsolute("//foo:foo", ImmutableMap.of()));
+ fs.stubStat(barBuildFile, inconsistentFileStatus);
+ Set<Label> labels = ImmutableSet.of(Label.parseAbsolute("//bar:baz", ImmutableMap.of()));
getSkyframeExecutor()
.getPackageManager()
.newTransitiveLoader()