diff options
author | 2017-12-21 10:52:16 -0800 | |
---|---|---|
committer | 2017-12-21 10:54:16 -0800 | |
commit | 4abd6c30f99635b803b9170baa3de1e3f3b2859d (patch) | |
tree | 843d18ad6b49d0cda1298ebd2440e46b5ef4a54b /src/main/java/com/google/devtools/build/lib/skyframe/FileStateValue.java | |
parent | 62dfea75efc831b153306985241d24ee7deb5bc5 (diff) |
Move FileStateValue.Type to Metadata; add Metadata.getType()
This is in preparation for merging FileArtifactValue and FileStateValue.
Progress on #3360.
PiperOrigin-RevId: 179832948
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/FileStateValue.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/FileStateValue.java | 83 |
1 files changed, 48 insertions, 35 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/FileStateValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/FileStateValue.java index c309b427ad..2595663fd4 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/FileStateValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/FileStateValue.java @@ -14,7 +14,9 @@ package com.google.devtools.build.lib.skyframe; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; +import com.google.devtools.build.lib.actions.FileStateType; import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor; import com.google.devtools.build.lib.vfs.FileStatus; @@ -33,10 +35,10 @@ import java.util.Objects; import javax.annotation.Nullable; /** - * Encapsulates the filesystem operations needed to get state for a path. This is at least a - * 'lstat' to determine what type of file the path is. + * Encapsulates the filesystem operations needed to get state for a path. This is equivalent to an + * 'lstat' that does not follow symlinks to determine what type of file the path is. * <ul> - * <li> For a non-existent file, the non existence is noted. + * <li> For a non-existent file, the non-existence is noted. * <li> For a symlink, the symlink target is noted. * <li> For a directory, the existence is noted. * <li> For a file, the existence is noted, along with metadata about the file (e.g. @@ -58,15 +60,6 @@ public abstract class FileStateValue implements SkyValue { public static final NonexistentFileStateValue NONEXISTENT_FILE_STATE_NODE = new NonexistentFileStateValue(); - /** Type of a path. */ - public enum Type { - REGULAR_FILE, - SPECIAL_FILE, - DIRECTORY, - SYMLINK, - NONEXISTENT, - } - protected FileStateValue() { } @@ -106,8 +99,9 @@ public abstract class FileStateValue implements SkyValue { return LegacySkyKey.create(SkyFunctions.FILE_STATE, rootedPath); } - public abstract Type getType(); + public abstract FileStateType getType(); + /** Returns the target of the symlink, or throws an exception if this is not a symlink. */ PathFragment getSymlinkTarget() { throw new IllegalStateException(); } @@ -205,8 +199,8 @@ public abstract class FileStateValue implements SkyValue { } @Override - public Type getType() { - return Type.REGULAR_FILE; + public FileStateType getType() { + return FileStateType.REGULAR_FILE; } @Override @@ -230,12 +224,17 @@ public abstract class FileStateValue implements SkyValue { @Override public boolean equals(Object obj) { - if (obj instanceof RegularFileStateValue) { - RegularFileStateValue other = (RegularFileStateValue) obj; - return size == other.size && mtime == other.mtime && Arrays.equals(digest, other.digest) - && Objects.equals(contentsProxy, other.contentsProxy); + if (obj == this) { + return true; } - return false; + if (!(obj instanceof RegularFileStateValue)) { + return false; + } + RegularFileStateValue other = (RegularFileStateValue) obj; + return size == other.size + && mtime == other.mtime + && Arrays.equals(digest, other.digest) + && Objects.equals(contentsProxy, other.contentsProxy); } @Override @@ -244,6 +243,15 @@ public abstract class FileStateValue implements SkyValue { } @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("digest", digest) + .add("size", size) + .add("mtime", mtime) + .add("contentsProxy", contentsProxy).toString(); + } + + @Override public String prettyPrint() { String contents = digest != null ? String.format("digest of %s", Arrays.toString(digest)) @@ -261,11 +269,10 @@ public abstract class FileStateValue implements SkyValue { this.contentsProxy = contentsProxy; } - static SpecialFileStateValue fromStat(PathFragment path, FileStatusWithDigest stat, + static SpecialFileStateValue fromStat(PathFragment path, FileStatus stat, @Nullable TimestampGranularityMonitor tsgm) throws IOException { long mtime = stat.getLastModifiedTime(); - // Note that TimestampGranularityMonitor#notifyDependenceOnFileTime is a thread-safe - // method. + // Note that TimestampGranularityMonitor#notifyDependenceOnFileTime is a thread-safe method. if (tsgm != null) { tsgm.notifyDependenceOnFileTime(path, mtime); } @@ -273,8 +280,8 @@ public abstract class FileStateValue implements SkyValue { } @Override - public Type getType() { - return Type.SPECIAL_FILE; + public FileStateType getType() { + return FileStateType.SPECIAL_FILE; } @Override @@ -294,11 +301,14 @@ public abstract class FileStateValue implements SkyValue { @Override public boolean equals(Object obj) { - if (obj instanceof SpecialFileStateValue) { - SpecialFileStateValue other = (SpecialFileStateValue) obj; - return Objects.equals(contentsProxy, other.contentsProxy); + if (obj == this) { + return true; } - return false; + if (!(obj instanceof SpecialFileStateValue)) { + return false; + } + SpecialFileStateValue other = (SpecialFileStateValue) obj; + return Objects.equals(contentsProxy, other.contentsProxy); } @Override @@ -319,8 +329,8 @@ public abstract class FileStateValue implements SkyValue { } @Override - public Type getType() { - return Type.DIRECTORY; + public FileStateType getType() { + return FileStateType.DIRECTORY; } @Override @@ -350,8 +360,8 @@ public abstract class FileStateValue implements SkyValue { } @Override - public Type getType() { - return Type.SYMLINK; + public FileStateType getType() { + return FileStateType.SYMLINK; } @Override @@ -386,8 +396,8 @@ public abstract class FileStateValue implements SkyValue { } @Override - public Type getType() { - return Type.NONEXISTENT; + public FileStateType getType() { + return FileStateType.NONEXISTENT; } @Override @@ -398,6 +408,9 @@ public abstract class FileStateValue implements SkyValue { // This object is normally a singleton, but deserialization produces copies. @Override public boolean equals(Object obj) { + if (obj == this) { + return true; + } return obj instanceof NonexistentFileStateValue; } |