Refactor: ResolvedFile.getMetadata is now .getMetadataHash.
This is a subtle change that'll go a long way: there's a bug in the handling of
directory symlinks (changes in the link target are not picked up) which I'll
fix by combining the metadata hashes of all items in the directory, and use
that as the directory symlink's metadata hash.
--
MOS_MIGRATED_REVID=109564943
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalValue.java
index 8c1ad84..cfd2ce0 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalValue.java
@@ -269,8 +269,8 @@
@Override
@Nullable
- public FileStateValue getMetadata() {
- return metadata;
+ public Integer getMetadataHash() {
+ return metadata == null ? null : Integer.valueOf(metadata.hashCode());
}
@Override
@@ -329,8 +329,8 @@
}
@Override
- public FileStateValue getMetadata() {
- return FileStateValue.DIRECTORY_FILE_STATE_NODE;
+ public Integer getMetadataHash() {
+ return Integer.valueOf(FileStateValue.DIRECTORY_FILE_STATE_NODE.hashCode());
}
@Override
@@ -374,7 +374,6 @@
private final Symlink symlink;
@Nullable private final FileStateValue metadata;
- /** C'tor for {@link #stripMetadataForTesting()}. */
private DanglingSymlink(Symlink symlink) {
this.symlink = symlink;
this.metadata = null;
@@ -404,8 +403,8 @@
@Override
@Nullable
- public FileStateValue getMetadata() {
- return metadata;
+ public Integer getMetadataHash() {
+ return metadata == null ? null : Integer.valueOf(metadata.hashCode());
}
@Override
@@ -490,8 +489,8 @@
@Override
@Nullable
- public FileStateValue getMetadata() {
- return metadata;
+ public Integer getMetadataHash() {
+ return metadata == null ? null : Integer.valueOf(metadata.hashCode());
}
@Override
@@ -535,27 +534,27 @@
private static final class SymlinkToDirectory implements ResolvedFile {
private final RootedPath path;
- @Nullable private final FileStateValue metadata;
+ @Nullable private final Integer metadataHash;
private final Symlink symlink;
/** C'tor for {@link #stripMetadataForTesting()}. */
private SymlinkToDirectory(RootedPath targetPath, Symlink symlink) {
this.path = Preconditions.checkNotNull(targetPath);
- this.metadata = null;
+ this.metadataHash = null;
this.symlink = symlink;
}
private SymlinkToDirectory(
RootedPath targetPath, RootedPath linkNamePath, PathFragment linkValue) {
this.path = Preconditions.checkNotNull(targetPath);
- this.metadata = null;
+ this.metadataHash = null;
this.symlink = new Symlink(linkNamePath, linkValue);
}
SymlinkToDirectory(RootedPath targetPath, RootedPath linkNamePath,
- PathFragment linkValue, FileStateValue metadata) {
+ PathFragment linkValue, Integer metadataHash) {
this.path = Preconditions.checkNotNull(targetPath);
- this.metadata = Preconditions.checkNotNull(metadata);
+ this.metadataHash = Preconditions.checkNotNull(metadataHash);
this.symlink = new Symlink(linkNamePath, linkValue);
}
@@ -571,8 +570,8 @@
@Override
@Nullable
- public FileStateValue getMetadata() {
- return metadata;
+ public Integer getMetadataHash() {
+ return metadataHash;
}
@Override
@@ -584,13 +583,13 @@
return false;
}
return this.path.equals(((SymlinkToDirectory) obj).path)
- && Objects.equal(this.metadata, ((SymlinkToDirectory) obj).metadata)
+ && Objects.equal(this.metadataHash, ((SymlinkToDirectory) obj).metadataHash)
&& this.symlink.equals(((SymlinkToDirectory) obj).symlink);
}
@Override
public int hashCode() {
- return Objects.hashCode(path, metadata, symlink);
+ return Objects.hashCode(path, metadataHash, symlink);
}
@Override
@@ -631,8 +630,8 @@
}
public static ResolvedFile symlinkToDirectory(RootedPath targetPath,
- RootedPath linkNamePath, PathFragment linkValue, FileStateValue metadata) {
- return new SymlinkToDirectory(targetPath, linkNamePath, linkValue, metadata);
+ RootedPath linkNamePath, PathFragment linkValue, Integer metadataHash) {
+ return new SymlinkToDirectory(targetPath, linkNamePath, linkValue, metadataHash);
}
public static ResolvedFile danglingSymlink(RootedPath linkNamePath, PathFragment linkValue,
@@ -684,16 +683,16 @@
RootedPath getPath();
/**
- * Associated metadata.
+ * Hash code of associated metadata.
*
- * <p>This field must be stored so that this {@link ResolvedFile} is (also) the function of the
- * stat() of the file, but otherwise it is likely not something the consumer of the
- * {@link ResolvedFile} is directly interested in.
+ * <p>This is usually some hash of the {@link FileStateValue} of the underlying filesystem
+ * entity.
*
- * <p>May only return null if metadata is stripped for tests.
+ * <p>The method only returns null if tests stripped the metadata, or the {@link ResolvedFile}
+ * was created by the {@link ResolvedFileFactoryForTesting}.
*/
@Nullable
- FileStateValue getMetadata();
+ Integer getMetadataHash();
/**
* Returns the path of the Fileset-output symlink relative to the output directory.