Search in sources :

Example 11 with FileStatus

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;
}
Also used : FileStatus(com.google.devtools.build.lib.vfs.FileStatus) DosFileAttributes(java.nio.file.attribute.DosFileAttributes) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File)

Example 12 with FileStatus

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

Example 13 with FileStatus

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();
        }
    }
}
Also used : FileStatus(com.google.devtools.build.lib.vfs.FileStatus) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream)

Example 14 with FileStatus

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

Example 15 with FileStatus

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