use of com.google.devtools.build.lib.vfs.FileStatus in project bazel by bazelbuild.
the class FileArtifactValue method create.
@VisibleForTesting
public static FileArtifactValue create(Artifact artifact) throws IOException {
Path path = artifact.getPath();
FileStatus stat = path.stat();
boolean isFile = stat.isFile();
return create(artifact, isFile, isFile ? stat.getSize() : 0, null);
}
use of com.google.devtools.build.lib.vfs.FileStatus in project bazel by bazelbuild.
the class FileStateValue method create.
public static FileStateValue create(RootedPath rootedPath, @Nullable TimestampGranularityMonitor tsgm) throws InconsistentFilesystemException, IOException {
Path path = rootedPath.asPath();
// Stat, but don't throw an exception for the common case of a nonexistent file. This still
// throws an IOException in case any other IO error is encountered.
FileStatus stat = path.statIfFound(Symlinks.NOFOLLOW);
if (stat == null) {
return NONEXISTENT_FILE_STATE_NODE;
}
return createWithStatNoFollow(rootedPath, FileStatusWithDigestAdapter.adapt(stat), tsgm);
}
use of com.google.devtools.build.lib.vfs.FileStatus in project bazel by bazelbuild.
the class DarwinSandboxedStrategy method finalizeLinks.
private Map<PathFragment, Path> finalizeLinks(Map<PathFragment, Path> unfinalized) throws IOException {
HashMap<PathFragment, Path> finalizedLinks = new HashMap<>();
for (Map.Entry<PathFragment, Path> mount : unfinalized.entrySet()) {
PathFragment target = mount.getKey();
Path source = mount.getValue();
// have to deal with finalizing the link.
if (source == null) {
finalizedLinks.put(target, source);
continue;
}
FileStatus stat = source.statNullable(Symlinks.NOFOLLOW);
if (stat != null && stat.isDirectory()) {
for (Path subSource : FileSystemUtils.traverseTree(source, Predicates.alwaysTrue())) {
PathFragment subTarget = target.getRelative(subSource.relativeTo(source));
finalizeLinksPath(finalizedLinks, subTarget, subSource, subSource.statNullable(Symlinks.NOFOLLOW));
}
} else {
finalizeLinksPath(finalizedLinks, target, source, stat);
}
}
return finalizedLinks;
}
use of com.google.devtools.build.lib.vfs.FileStatus in project bazel by bazelbuild.
the class SymlinkedExecRoot method createInputs.
private void createInputs(Map<PathFragment, Path> inputs) throws IOException {
// All input files are relative to the execroot.
for (Entry<PathFragment, Path> entry : inputs.entrySet()) {
Path key = sandboxExecRoot.getRelative(entry.getKey());
FileStatus keyStat = key.statNullable(Symlinks.NOFOLLOW);
if (keyStat != null) {
if (keyStat.isSymbolicLink() && entry.getValue() != null && key.readSymbolicLink().equals(entry.getValue().asFragment())) {
continue;
}
key.delete();
}
// A null value means that we're supposed to create an empty file as the input.
if (entry.getValue() != null) {
key.createSymbolicLink(entry.getValue());
} else {
FileSystemUtils.createEmptyFile(key);
}
}
}
use of com.google.devtools.build.lib.vfs.FileStatus in project bazel by bazelbuild.
the class TreeArtifactMetadataTest method testIOExceptionEndToEnd.
/**
* Tests that ArtifactFunction rethrows transitive {@link IOException}s as
* {@link MissingInputFileException}s.
*/
@Test
public void testIOExceptionEndToEnd() throws Throwable {
final IOException exception = new IOException("boop");
setupRoot(new CustomInMemoryFs() {
@Override
public FileStatus stat(Path path, boolean followSymlinks) throws IOException {
if (path.getBaseName().equals("one")) {
throw exception;
}
return super.stat(path, followSymlinks);
}
});
try {
Artifact artifact = createTreeArtifact("outOne");
TreeArtifactValue value = evaluateTreeArtifact(artifact, ImmutableList.of(new PathFragment("one")));
fail("MissingInputFileException expected, got " + value);
} catch (Exception e) {
assertThat(Throwables.getRootCause(e).getMessage()).contains(exception.getMessage());
}
}
Aggregations