Search in sources :

Example 41 with FileSystem

use of java.nio.file.FileSystem in project buck by facebook.

the class EdenMountTest method getSha1DelegatesToThriftClient.

@Test
public void getSha1DelegatesToThriftClient() throws EdenError, TException {
    List<MountInfo> mountInfos = ImmutableList.of(new MountInfo("/home/mbolin/src/buck", /* edenClientPath */
    ""));
    EdenService.Client thriftClient = createMock(EdenService.Client.class);
    expect(thriftClient.listMounts()).andReturn(mountInfos);
    FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
    Path entry = fs.getPath("LICENSE");
    HashCode hash = HashCode.fromString("2b8b815229aa8a61e483fb4ba0588b8b6c491890");
    SHA1Result sha1Result = new SHA1Result();
    sha1Result.setSha1(hash.asBytes());
    expect(thriftClient.getSHA1("/home/mbolin/src/buck", ImmutableList.of("LICENSE"))).andReturn(ImmutableList.of(sha1Result));
    replay(thriftClient);
    EdenClient client = new EdenClient(thriftClient);
    Path pathToBuck = fs.getPath("/home/mbolin/src/buck");
    EdenMount mount = client.getMountFor(pathToBuck);
    assertNotNull("Should find mount for path.", mount);
    assertEquals(Sha1HashCode.fromHashCode(hash), mount.getSha1(entry));
    verify(thriftClient);
}
Also used : Path(java.nio.file.Path) HashCode(com.google.common.hash.HashCode) Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode) FileSystem(java.nio.file.FileSystem) MountInfo(com.facebook.eden.thrift.MountInfo) EdenService(com.facebook.eden.thrift.EdenService) SHA1Result(com.facebook.eden.thrift.SHA1Result) Test(org.junit.Test)

Example 42 with FileSystem

use of java.nio.file.FileSystem in project buck by facebook.

the class EdenProjectFilesystemDelegateTest method computeSha1ForSymlinkUnderMountThatPointsToFileUnderMount.

@Test
public void computeSha1ForSymlinkUnderMountThatPointsToFileUnderMount() throws EdenError, TException, IOException {
    FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
    Path root = fs.getPath(JIMFS_WORKING_DIRECTORY);
    ProjectFilesystemDelegate delegate = new DefaultProjectFilesystemDelegate(root);
    // Create a symlink within the project root.
    Path link = fs.getPath("/work/link");
    Path target = fs.getPath("/work/target");
    Files.createFile(target);
    Files.createSymbolicLink(link, target);
    // Eden will throw when the SHA-1 for the link is requested, but return a SHA-1 when the target
    // is requested.
    EdenMount mount = createMock(EdenMount.class);
    expect(mount.getBindMounts()).andReturn(ImmutableList.of());
    expect(mount.getPathRelativeToProjectRoot(link)).andReturn(Optional.of(fs.getPath("link")));
    expect(mount.getPathRelativeToProjectRoot(target)).andReturn(Optional.of(fs.getPath("target")));
    expect(mount.getSha1(fs.getPath("link"))).andThrow(new EdenError());
    expect(mount.getSha1(fs.getPath("target"))).andReturn(DUMMY_SHA1);
    replay(mount);
    EdenProjectFilesystemDelegate edenDelegate = new EdenProjectFilesystemDelegate(mount, delegate);
    assertEquals(DUMMY_SHA1, edenDelegate.computeSha1(link));
    verify(mount);
}
Also used : Path(java.nio.file.Path) EdenError(com.facebook.eden.thrift.EdenError) FileSystem(java.nio.file.FileSystem) DefaultProjectFilesystemDelegate(com.facebook.buck.io.DefaultProjectFilesystemDelegate) ProjectFilesystemDelegate(com.facebook.buck.io.ProjectFilesystemDelegate) DefaultProjectFilesystemDelegate(com.facebook.buck.io.DefaultProjectFilesystemDelegate) Test(org.junit.Test)

Example 43 with FileSystem

use of java.nio.file.FileSystem in project buck by facebook.

the class EdenProjectFilesystemDelegateTest method computeSha1ForSymlinkUnderMountThatPointsToFileOutsideMount.

@Test
public void computeSha1ForSymlinkUnderMountThatPointsToFileOutsideMount() throws IOException, EdenError, TException {
    FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
    Path root = fs.getPath(JIMFS_WORKING_DIRECTORY);
    ProjectFilesystemDelegate delegate = new DefaultProjectFilesystemDelegate(root);
    // Create a symlink within the project root.
    Path link = fs.getPath("/work/link");
    Path target = fs.getPath("/example");
    Files.createFile(target);
    byte[] bytes = new byte[] { 66, 85, 67, 75 };
    Files.write(target, bytes);
    Files.createSymbolicLink(link, target);
    // Eden will throw when the SHA-1 for the link is requested, but return a SHA-1 when the target
    // is requested.
    EdenMount mount = createMock(EdenMount.class);
    expect(mount.getBindMounts()).andReturn(ImmutableList.of());
    expect(mount.getPathRelativeToProjectRoot(link)).andReturn(Optional.of(fs.getPath("link")));
    expect(mount.getPathRelativeToProjectRoot(target)).andReturn(Optional.empty());
    expect(mount.getSha1(fs.getPath("link"))).andThrow(new EdenError());
    replay(mount);
    EdenProjectFilesystemDelegate edenDelegate = new EdenProjectFilesystemDelegate(mount, delegate);
    assertEquals("EdenProjectFilesystemDelegate.computeSha1() should return the SHA-1 of the target of " + "the symlink even though the target is outside of the EdenFS root.", Sha1HashCode.fromHashCode(Hashing.sha1().hashBytes(bytes)), edenDelegate.computeSha1(link));
    verify(mount);
}
Also used : Path(java.nio.file.Path) EdenError(com.facebook.eden.thrift.EdenError) FileSystem(java.nio.file.FileSystem) DefaultProjectFilesystemDelegate(com.facebook.buck.io.DefaultProjectFilesystemDelegate) ProjectFilesystemDelegate(com.facebook.buck.io.ProjectFilesystemDelegate) DefaultProjectFilesystemDelegate(com.facebook.buck.io.DefaultProjectFilesystemDelegate) Test(org.junit.Test)

Example 44 with FileSystem

use of java.nio.file.FileSystem in project buck by facebook.

the class StackedDownloaderTest method createDownloadersForEachEntryInTheMavenRepositoriesSection.

@Test
public void createDownloadersForEachEntryInTheMavenRepositoriesSection() throws IOException {
    boolean isWindows = Platform.detect() == Platform.WINDOWS;
    Configuration configuration = isWindows ? Configuration.windows() : Configuration.unix();
    FileSystem vfs = Jimfs.newFileSystem(configuration);
    Path m2Root = vfs.getPath(jimfAbsolutePath("/home/user/.m2/repository"));
    Files.createDirectories(m2Root);
    // Set up a config so we expect to see both a local and a remote maven repo.
    Path projectRoot = vfs.getPath(jimfAbsolutePath("/opt/local/src"));
    Files.createDirectories(projectRoot);
    BuckConfig config = FakeBuckConfig.builder().setFilesystem(new ProjectFilesystem(projectRoot)).setSections("[maven_repositories]", "local = " + m2Root.toString(), "central = https://repo1.maven.org/maven2").build();
    Downloader downloader = StackedDownloader.createFromConfig(config, Optional.empty());
    List<Downloader> downloaders = unpackDownloaders(downloader);
    boolean seenRemote = false;
    boolean seenLocal = false;
    for (Downloader seen : downloaders) {
        if (seen instanceof RemoteMavenDownloader) {
            seenRemote = true;
        } else if (seen instanceof OnDiskMavenDownloader) {
            seenLocal = true;
        }
    }
    assertTrue(seenLocal);
    assertTrue(seenRemote);
}
Also used : Path(java.nio.file.Path) Configuration(com.google.common.jimfs.Configuration) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) FileSystem(java.nio.file.FileSystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 45 with FileSystem

use of java.nio.file.FileSystem in project buck by facebook.

the class AsynchronousDirectoryContentsCleanerTest method contentsOfTrashDirectoryCleanedAsynchronously.

@Test
public void contentsOfTrashDirectoryCleanedAsynchronously() throws Exception {
    FileSystem vfs = Jimfs.newFileSystem(Configuration.unix());
    Path dirToDelete = vfs.getPath("/tmp/fake-tmp-dir");
    Path fooDir = dirToDelete.resolve("foo");
    Path fooBarDir = fooDir.resolve("bar");
    Files.createDirectories(fooBarDir.resolve("baz"));
    Path fooBarBlechTxtFile = fooBarDir.resolve("blech.txt");
    Files.write(fooBarBlechTxtFile, "hello world\n".getBytes(UTF_8));
    AsynchronousDirectoryContentsCleaner cleaner = new AsynchronousDirectoryContentsCleaner(MoreExecutors.directExecutor());
    assertThat(Files.exists(dirToDelete), is(true));
    assertThat(Files.exists(fooBarDir), is(true));
    assertThat(Files.exists(fooBarBlechTxtFile), is(true));
    // This executes synchronously, since we passed in a direct executor above.
    cleaner.startCleaningDirectory(dirToDelete);
    assertThat(Files.exists(dirToDelete), is(true));
    assertThat(Files.exists(fooBarDir), is(false));
    assertThat(Files.exists(fooBarBlechTxtFile), is(false));
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Aggregations

FileSystem (java.nio.file.FileSystem)159 Path (java.nio.file.Path)112 Test (org.junit.Test)66 IOException (java.io.IOException)25 File (java.io.File)17 ArrayList (java.util.ArrayList)14 FilterFileSystem (org.apache.lucene.mockfile.FilterFileSystem)13 URI (java.net.URI)11 FilterPath (org.apache.lucene.mockfile.FilterPath)11 InputStream (java.io.InputStream)10 OutputStream (java.io.OutputStream)10 FileStore (java.nio.file.FileStore)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)6 HashMap (java.util.HashMap)6 DefaultProjectFilesystemDelegate (com.facebook.buck.io.DefaultProjectFilesystemDelegate)5 ProjectFilesystemDelegate (com.facebook.buck.io.ProjectFilesystemDelegate)5 WindowsFS (org.apache.lucene.mockfile.WindowsFS)5 FSDirectory (org.apache.lucene.store.FSDirectory)5 BuckConfig (com.facebook.buck.cli.BuckConfig)4 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)4