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())); }
/** * Create a FileFileStateValue instance corresponding to the given existing file. * * @param stat must be of type "File". (Not a symlink). */ private static RegularFileStateValue fromPath( Path path, FileStatusWithDigest stat, @Nullable TimestampGranularityMonitor tsgm) throws InconsistentFilesystemException { Preconditions.checkState(stat.isFile(), path); try { byte[] digest = stat.getDigest(); if (digest == null) { digest = path.getFastDigest(); } if (digest == null) { long mtime = stat.getLastModifiedTime(); // Note that TimestampGranularityMonitor#notifyDependenceOnFileTime is a thread-safe // method. if (tsgm != null) { tsgm.notifyDependenceOnFileTime(mtime); } 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 RegularFileStateValue( stat.getSize(), stat.getLastModifiedTime(), digest, null); } } catch (IOException e) { String errorMessage = e.getMessage() != null ? "error '" + e.getMessage() + "'" : "an error"; throw new InconsistentFilesystemException( "'stat' said " + path + " is a file but then we " + "later encountered " + errorMessage + " which indicates that " + path + " is no " + "longer a file. Did you delete it during the build?"); } }