Search in sources :

Example 1 with FileSystem

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

the class AppleSdkDiscoveryTest method shouldScanRealDirectoryOnlyOnce.

@Test
public void shouldScanRealDirectoryOnlyOnce() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "sdk-discovery-symlink", temp);
    workspace.setUp();
    Path root = workspace.getPath("");
    FileSystem fileSystem = root.getFileSystem();
    Path actualSdkPath = root.resolve("MacOSX10.9.sdk");
    Path sdksDir = root.resolve("Platforms/MacOSX.platform/Developer/SDKs");
    Files.createDirectories(sdksDir);
    // create relative symlink
    Files.createSymbolicLink(sdksDir.resolve("MacOSX10.9.sdk"), fileSystem.getPath("MacOSX.sdk"));
    // create absolute symlink
    Files.createSymbolicLink(sdksDir.resolve("MacOSX.sdk"), actualSdkPath);
    ImmutableMap<String, AppleToolchain> toolchains = ImmutableMap.of("com.apple.dt.toolchain.XcodeDefault", getDefaultToolchain(root));
    ImmutableMap<AppleSdk, AppleSdkPaths> actual = AppleSdkDiscovery.discoverAppleSdkPaths(Optional.of(root), ImmutableList.of(root), toolchains, new FakeAppleConfig());
    // if both symlinks were to be visited, exception would have been thrown during discovery
    assertThat(actual.size(), is(2));
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Example 2 with FileSystem

use of java.nio.file.FileSystem in project cryptomator by cryptomator.

the class Vault method unlock.

public synchronized void unlock(CharSequence passphrase) {
    try {
        FileSystem fs = getCryptoFileSystem(passphrase);
        if (!server.isRunning()) {
            server.start();
        }
        servlet = server.createWebDavServlet(fs.getPath("/"), vaultSettings.getId() + "/" + vaultSettings.mountName().get());
        servlet.start();
        Platform.runLater(() -> {
            unlocked.set(true);
        });
    } catch (IOException e) {
        LOG.error("Unable to provide filesystem", e);
    }
}
Also used : CryptoFileSystem(org.cryptomator.cryptofs.CryptoFileSystem) FileSystem(java.nio.file.FileSystem) IOException(java.io.IOException)

Example 3 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 4 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 5 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)

Aggregations

FileSystem (java.nio.file.FileSystem)353 Path (java.nio.file.Path)241 Test (org.junit.Test)116 IOException (java.io.IOException)84 URI (java.net.URI)47 File (java.io.File)32 ArrayList (java.util.ArrayList)31 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)26 InputStream (java.io.InputStream)18 FileVisitResult (java.nio.file.FileVisitResult)18 HashMap (java.util.HashMap)18 Before (org.junit.Before)16 OutputStream (java.io.OutputStream)13 FilterFileSystem (org.apache.lucene.mockfile.FilterFileSystem)13 URISyntaxException (java.net.URISyntaxException)11 FileStore (java.nio.file.FileStore)11 FilterPath (org.apache.lucene.mockfile.FilterPath)11 URL (java.net.URL)10 PathMatcher (java.nio.file.PathMatcher)10 CryptoFileSystemProvider.newFileSystem (org.cryptomator.cryptofs.CryptoFileSystemProvider.newFileSystem)10