diff options
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 | 82 |
1 files changed, 70 insertions, 12 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 1a75e3b0de..3fffcd9c00 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 @@ -41,7 +41,7 @@ import javax.annotation.Nullable; * <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. - * file digest). See {@link FileFileStateValue}. + * file digest). See {@link RegularFileStateValue}. * <ul> * * <p>This class is an implementation detail of {@link FileValue} and should not be used outside of @@ -59,7 +59,8 @@ public abstract class FileStateValue implements SkyValue { new NonexistentFileStateValue(); enum Type { - FILE, + REGULAR_FILE, + SPECIAL_FILE, DIRECTORY, SYMLINK, NONEXISTENT, @@ -86,7 +87,9 @@ public abstract class FileStateValue implements SkyValue { throws InconsistentFilesystemException, IOException { Path path = rootedPath.asPath(); if (statNoFollow.isFile()) { - return FileFileStateValue.fromPath(path, statNoFollow, tsgm); + return statNoFollow.isSpecialFile() + ? SpecialFileStateValue.fromStat(statNoFollow, tsgm) + : RegularFileStateValue.fromPath(path, statNoFollow, tsgm); } else if (statNoFollow.isDirectory()) { return DIRECTORY_FILE_STATE_NODE; } else if (statNoFollow.isSymbolicLink()) { @@ -125,7 +128,7 @@ public abstract class FileStateValue implements SkyValue { abstract String prettyPrint(); /** - * Implementation of {@link FileStateValue} for files that exist. + * Implementation of {@link FileStateValue} for regular files that exist. * * <p>A union of (digest, mtime). We use digests only if a fast digest lookup is available from * the filesystem. If not, we fall back to mtime-based digests. This avoids the case where Blaze @@ -133,7 +136,7 @@ public abstract class FileStateValue implements SkyValue { * where fast digest lookups are not available. */ @ThreadSafe - public static final class FileFileStateValue extends FileStateValue { + public static final class RegularFileStateValue extends FileStateValue { private final long size; // Only needed for empty-file equality-checking. Otherwise is always -1. // TODO(bazel-team): Consider getting rid of this special case for empty files. @@ -141,7 +144,7 @@ public abstract class FileStateValue implements SkyValue { @Nullable private final byte[] digest; @Nullable private final FileContentsProxy contentsProxy; - private FileFileStateValue(long size, long mtime, byte[] digest, + private RegularFileStateValue(long size, long mtime, byte[] digest, FileContentsProxy contentsProxy) { Preconditions.checkState((digest == null) != (contentsProxy == null)); this.size = size; @@ -156,7 +159,7 @@ public abstract class FileStateValue implements SkyValue { * Create a FileFileStateValue instance corresponding to the given existing file. * @param stat must be of type "File". (Not a symlink). */ - private static FileFileStateValue fromPath(Path path, FileStatusWithDigest stat, + private static RegularFileStateValue fromPath(Path path, FileStatusWithDigest stat, @Nullable TimestampGranularityMonitor tsgm) throws InconsistentFilesystemException { Preconditions.checkState(stat.isFile(), path); @@ -172,13 +175,13 @@ public abstract class FileStateValue implements SkyValue { if (tsgm != null) { tsgm.notifyDependenceOnFileTime(mtime); } - return new FileFileStateValue(stat.getSize(), stat.getLastModifiedTime(), null, + return new RegularFileStateValue(stat.getSize(), stat.getLastModifiedTime(), null, FileContentsProxy.create(mtime, stat.getNodeId())); } else { // We are careful here to avoid putting the value ID into FileMetadata if we already have // a digest. Arbitrary filesystems may do weird things with the value ID; a digest is more // robust. - return new FileFileStateValue(stat.getSize(), stat.getLastModifiedTime(), digest, null); + return new RegularFileStateValue(stat.getSize(), stat.getLastModifiedTime(), digest, null); } } catch (IOException e) { String errorMessage = e.getMessage() != null @@ -191,7 +194,7 @@ public abstract class FileStateValue implements SkyValue { @Override Type getType() { - return Type.FILE; + return Type.REGULAR_FILE; } @Override @@ -207,8 +210,8 @@ public abstract class FileStateValue implements SkyValue { @Override public boolean equals(Object obj) { - if (obj instanceof FileFileStateValue) { - FileFileStateValue other = (FileFileStateValue) 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); } @@ -230,6 +233,61 @@ public abstract class FileStateValue implements SkyValue { } } + /** Implementation of {@link FileStateValue} for special files that exist. */ + public static final class SpecialFileStateValue extends FileStateValue { + private final FileContentsProxy contentsProxy; + + private SpecialFileStateValue(FileContentsProxy contentsProxy) { + this.contentsProxy = contentsProxy; + } + + static SpecialFileStateValue fromStat(FileStatusWithDigest stat, + @Nullable TimestampGranularityMonitor tsgm) throws IOException { + long mtime = stat.getLastModifiedTime(); + // Note that TimestampGranularityMonitor#notifyDependenceOnFileTime is a thread-safe + // method. + if (tsgm != null) { + tsgm.notifyDependenceOnFileTime(mtime); + } + return new SpecialFileStateValue(FileContentsProxy.create(mtime, stat.getNodeId())); + } + + @Override + Type getType() { + return Type.SPECIAL_FILE; + } + + @Override + long getSize() { + return 0; + } + + @Override + @Nullable + byte[] getDigest() { + return null; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof SpecialFileStateValue) { + SpecialFileStateValue other = (SpecialFileStateValue) obj; + return Objects.equals(contentsProxy, other.contentsProxy); + } + return false; + } + + @Override + public int hashCode() { + return contentsProxy.hashCode(); + } + + @Override + public String prettyPrint() { + return String.format("special file with %s", contentsProxy.prettyPrint()); + } + } + /** Implementation of {@link FileStateValue} for directories that exist. */ public static final class DirectoryFileStateValue extends FileStateValue { |