Search in sources :

Example 11 with FileSystem

use of com.google.devtools.build.lib.vfs.FileSystem in project bazel by bazelbuild.

the class DarwinSandboxedStrategy method getWritableDirs.

@Override
protected ImmutableSet<Path> getWritableDirs(Path sandboxExecRoot, Map<String, String> env) {
    FileSystem fs = sandboxExecRoot.getFileSystem();
    ImmutableSet.Builder<Path> writableDirs = ImmutableSet.builder();
    writableDirs.addAll(super.getWritableDirs(sandboxExecRoot, env));
    writableDirs.add(fs.getPath("/dev"));
    String sysTmpDir = System.getenv("TMPDIR");
    if (sysTmpDir != null) {
        writableDirs.add(fs.getPath(sysTmpDir));
    }
    writableDirs.add(fs.getPath("/tmp"));
    // ~/Library/Cache and ~/Library/Logs need to be writable (cf. issue #2231).
    Path homeDir = fs.getPath(System.getProperty("user.home"));
    writableDirs.add(homeDir.getRelative("Library/Cache"));
    writableDirs.add(homeDir.getRelative("Library/Logs"));
    // Other temporary directories from getconf.
    for (Path path : confPaths) {
        if (path.exists()) {
            writableDirs.add(path);
        }
    }
    return writableDirs.build();
}
Also used : SearchPath(com.google.devtools.build.lib.vfs.SearchPath) Path(com.google.devtools.build.lib.vfs.Path) ImmutableSet(com.google.common.collect.ImmutableSet) FileSystem(com.google.devtools.build.lib.vfs.FileSystem)

Example 12 with FileSystem

use of com.google.devtools.build.lib.vfs.FileSystem in project bazel by bazelbuild.

the class FsApparatus method newNative.

/**
   * When using a Native file system, absolute paths will be treated as absolute paths on the unix
   * file system, as opposed to paths relative to the backing temp directory. So for simplicity,
   * you ought to only use relative paths for FsApparatus#file, FsApparatus#dir, and
   * FsApparatus#path. Otherwise, be aware of the following issue
   *
   *   Path p1 = scratch.path(...);
   *   Path p2 = scratch.path(p1.getPathString());
   *
   * We'd like the invariant that p1.equals(p2) regardless if scratch is in-memory or not, but this
   * does not hold with our usage of Unix filesystems.
   */
public static FsApparatus newNative() {
    FileSystem fs = FileSystems.getNativeFileSystem();
    Path wd = fs.getPath(TMP_DIR);
    try {
        FileSystemUtils.deleteTree(wd);
    } catch (IOException e) {
        throw new AssertionError(e.getMessage());
    }
    return new FsApparatus(fs, wd);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) InMemoryFileSystem(com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem) FileSystem(com.google.devtools.build.lib.vfs.FileSystem) IOException(java.io.IOException)

Example 13 with FileSystem

use of com.google.devtools.build.lib.vfs.FileSystem in project bazel by bazelbuild.

the class IncrementalLoadingTest method createTester.

@Before
public final void createTester() throws Exception {
    ManualClock clock = new ManualClock();
    FileSystem fs = new InMemoryFileSystem(clock) {

        @Override
        public Collection<Dirent> readdir(Path path, boolean followSymlinks) throws IOException {
            if (path.equals(throwOnReaddir)) {
                throw new FileNotFoundException(path.getPathString());
            }
            return super.readdir(path, followSymlinks);
        }

        @Nullable
        @Override
        public FileStatus stat(Path path, boolean followSymlinks) throws IOException {
            if (path.equals(throwOnStat)) {
                throw new IOException("bork " + path.getPathString());
            }
            return super.stat(path, followSymlinks);
        }
    };
    tester = createTester(fs, clock);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ManualClock(com.google.devtools.build.lib.testutil.ManualClock) FileSystem(com.google.devtools.build.lib.vfs.FileSystem) InMemoryFileSystem(com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem) InMemoryFileSystem(com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem) Dirent(com.google.devtools.build.lib.vfs.Dirent) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Before(org.junit.Before)

Example 14 with FileSystem

use of com.google.devtools.build.lib.vfs.FileSystem in project bazel by bazelbuild.

the class PackageFactoryTestBase method initializeFileSystem.

@Before
public final void initializeFileSystem() throws Exception {
    FileSystem fs = new InMemoryFileSystem() {

        @Override
        public Collection<Dirent> readdir(Path path, boolean followSymlinks) throws IOException {
            if (path.equals(throwOnReaddir)) {
                throw new FileNotFoundException(path.getPathString());
            }
            return super.readdir(path, followSymlinks);
        }
    };
    Path tmpPath = fs.getPath("/tmp");
    scratch = new Scratch(tmpPath);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) Scratch(com.google.devtools.build.lib.testutil.Scratch) InMemoryFileSystem(com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem) FileSystem(com.google.devtools.build.lib.vfs.FileSystem) InMemoryFileSystem(com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem) Dirent(com.google.devtools.build.lib.vfs.Dirent) FileNotFoundException(java.io.FileNotFoundException) Before(org.junit.Before)

Example 15 with FileSystem

use of com.google.devtools.build.lib.vfs.FileSystem in project bazel by bazelbuild.

the class FileFunctionTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(bos);
    FileSystem oldFileSystem = Path.getFileSystemForSerialization();
    try {
        // InMemoryFS is not supported for serialization.
        FileSystem fs = FileSystems.getJavaIoFileSystem();
        Path.setFileSystemForSerialization(fs);
        pkgRoot = fs.getRootDirectory();
        FileValue a = valueForPath(fs.getPath("/"));
        Path tmp = fs.getPath(TestUtils.tmpDirFile().getAbsoluteFile() + "/file.txt");
        FileSystemUtils.writeContentAsLatin1(tmp, "test contents");
        FileValue b = valueForPath(tmp);
        Preconditions.checkState(b.isFile());
        FileValue c = valueForPath(fs.getPath("/does/not/exist"));
        oos.writeObject(a);
        oos.writeObject(b);
        oos.writeObject(c);
        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(bis);
        FileValue a2 = (FileValue) ois.readObject();
        FileValue b2 = (FileValue) ois.readObject();
        FileValue c2 = (FileValue) ois.readObject();
        assertEquals(a, a2);
        assertEquals(b, b2);
        assertEquals(c, c2);
        assertFalse(a2.equals(b2));
    } finally {
        Path.setFileSystemForSerialization(oldFileSystem);
    }
}
Also used : RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) ByteArrayInputStream(java.io.ByteArrayInputStream) FileSystem(com.google.devtools.build.lib.vfs.FileSystem) InMemoryFileSystem(com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Aggregations

FileSystem (com.google.devtools.build.lib.vfs.FileSystem)17 Path (com.google.devtools.build.lib.vfs.Path)17 InMemoryFileSystem (com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem)11 IOException (java.io.IOException)7 Test (org.junit.Test)6 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)4 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)4 TestAction (com.google.devtools.build.lib.actions.util.TestAction)3 HashFunction (com.google.devtools.build.lib.vfs.FileSystem.HashFunction)3 DirectoryListingValue (com.google.devtools.build.lib.skyframe.DirectoryListingValue)2 Dirent (com.google.devtools.build.lib.vfs.Dirent)2 FileNotFoundException (java.io.FileNotFoundException)2 Before (org.junit.Before)2 Predicate (com.google.common.base.Predicate)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)1 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)1 BlazeDirectories (com.google.devtools.build.lib.analysis.BlazeDirectories)1 ServerDirectories (com.google.devtools.build.lib.analysis.ServerDirectories)1