Search in sources :

Example 6 with FileStatus

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);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) FileStatus(com.google.devtools.build.lib.vfs.FileStatus) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 7 with FileStatus

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);
}
Also used : RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) FileStatus(com.google.devtools.build.lib.vfs.FileStatus)

Example 8 with FileStatus

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;
}
Also used : SearchPath(com.google.devtools.build.lib.vfs.SearchPath) Path(com.google.devtools.build.lib.vfs.Path) FileStatus(com.google.devtools.build.lib.vfs.FileStatus) HashMap(java.util.HashMap) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 9 with FileStatus

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);
        }
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) FileStatus(com.google.devtools.build.lib.vfs.FileStatus) PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Example 10 with FileStatus

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());
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) FileStatus(com.google.devtools.build.lib.vfs.FileStatus) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) IOException(java.io.IOException) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) MissingInputFileException(com.google.devtools.build.lib.actions.MissingInputFileException) SkyFunctionException(com.google.devtools.build.skyframe.SkyFunctionException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

FileStatus (com.google.devtools.build.lib.vfs.FileStatus)18 Path (com.google.devtools.build.lib.vfs.Path)13 Test (org.junit.Test)9 IOException (java.io.IOException)8 Artifact (com.google.devtools.build.lib.actions.Artifact)3 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)3 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)3 ErrorInfo (com.google.devtools.build.skyframe.ErrorInfo)3 SkyKey (com.google.devtools.build.skyframe.SkyKey)3 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)2 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)2 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)2 MissingInputFileException (com.google.devtools.build.lib.actions.MissingInputFileException)2 SkyValue (com.google.devtools.build.skyframe.SkyValue)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ActionExecutionContext (com.google.devtools.build.lib.actions.ActionExecutionContext)1 ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)1 InjectedStat (com.google.devtools.build.lib.actions.cache.InjectedStat)1 MetadataHandler (com.google.devtools.build.lib.actions.cache.MetadataHandler)1