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();
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations