use of com.google.devtools.build.lib.vfs.FileStatus in project bazel by bazelbuild.
the class WindowsFileSystem method stat.
@Override
protected FileStatus stat(Path path, boolean followSymlinks) throws IOException {
File file = getIoFile(path);
final DosFileAttributes attributes;
try {
attributes = getAttribs(file, followSymlinks);
} catch (IOException e) {
throw new FileNotFoundException(path + ERR_NO_SUCH_FILE_OR_DIR);
}
final boolean isSymbolicLink = !followSymlinks && fileIsSymbolicLink(file);
FileStatus status = new FileStatus() {
@Override
public boolean isFile() {
return attributes.isRegularFile() || (isSpecialFile() && !isDirectory());
}
@Override
public boolean isSpecialFile() {
return attributes.isOther();
}
@Override
public boolean isDirectory() {
return attributes.isDirectory();
}
@Override
public boolean isSymbolicLink() {
return isSymbolicLink;
}
@Override
public long getSize() throws IOException {
return attributes.size();
}
@Override
public long getLastModifiedTime() throws IOException {
return attributes.lastModifiedTime().toMillis();
}
@Override
public long getLastChangeTime() {
// This is the best we can do with Java NIO...
return attributes.lastModifiedTime().toMillis();
}
@Override
public long getNodeId() {
// TODO(bazel-team): Consider making use of attributes.fileKey().
return -1;
}
};
return status;
}
use of com.google.devtools.build.lib.vfs.FileStatus in project bazel by bazelbuild.
the class PathPackageLocator method getFilePath.
private Path getFilePath(PathFragment suffix, AtomicReference<? extends UnixGlob.FilesystemCalls> cache) {
for (Path pathEntry : pathEntries) {
Path buildFile = pathEntry.getRelative(suffix);
FileStatus stat = cache.get().statNullable(buildFile, Symlinks.FOLLOW);
if (stat != null && stat.isFile()) {
return buildFile;
}
}
return null;
}
use of com.google.devtools.build.lib.vfs.FileStatus in project bazel by bazelbuild.
the class TestStrategy method appendStderr.
/** In rare cases, we might write something to stderr. Append it to the real test.log. */
protected static void appendStderr(Path stdOut, Path stdErr) throws IOException {
FileStatus stat = stdErr.statNullable();
OutputStream out = null;
InputStream in = null;
if (stat != null) {
try {
if (stat.getSize() > 0) {
if (stdOut.exists()) {
stdOut.setWritable(true);
}
out = stdOut.getOutputStream(true);
in = stdErr.getInputStream();
ByteStreams.copy(in, out);
}
} finally {
Closeables.close(out, true);
Closeables.close(in, true);
stdErr.delete();
}
}
}
use of com.google.devtools.build.lib.vfs.FileStatus in project bazel by bazelbuild.
the class ArtifactFunctionTest method testIOException_EndToEnd.
/**
* Tests that ArtifactFunction rethrows transitive {@link IOException}s as
* {@link MissingInputFileException}s.
*/
@Test
public void testIOException_EndToEnd() throws Throwable {
final IOException exception = new IOException("beep");
setupRoot(new CustomInMemoryFs() {
@Override
public FileStatus stat(Path path, boolean followSymlinks) throws IOException {
if (path.getBaseName().equals("bad")) {
throw exception;
}
return super.stat(path, followSymlinks);
}
});
try {
evaluateArtifactValue(createSourceArtifact("bad"));
fail();
} catch (MissingInputFileException e) {
assertThat(e.getMessage()).contains(exception.getMessage());
}
}
use of com.google.devtools.build.lib.vfs.FileStatus in project bazel by bazelbuild.
the class ArtifactFunctionTest method testUnreadableInputWithFsWithAvailableDigest.
@Test
public void testUnreadableInputWithFsWithAvailableDigest() throws Throwable {
final byte[] expectedDigest = MessageDigest.getInstance("md5").digest("someunreadablecontent".getBytes(StandardCharsets.UTF_8));
setupRoot(new CustomInMemoryFs() {
@Override
public byte[] getMD5Digest(Path path) throws IOException {
return path.getBaseName().equals("unreadable") ? expectedDigest : super.getMD5Digest(path);
}
});
Artifact input = createSourceArtifact("unreadable");
Path inputPath = input.getPath();
file(inputPath, "dummynotused");
inputPath.chmod(0);
FileArtifactValue value = (FileArtifactValue) evaluateArtifactValue(input, /*mandatory=*/
true);
FileStatus stat = inputPath.stat();
assertThat(value.getSize()).isEqualTo(stat.getSize());
assertThat(value.getDigest()).isEqualTo(expectedDigest);
}
Aggregations