Search in sources :

Example 1 with ProjectFilesystemDelegate

use of com.facebook.buck.io.ProjectFilesystemDelegate 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 2 with ProjectFilesystemDelegate

use of com.facebook.buck.io.ProjectFilesystemDelegate 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 3 with ProjectFilesystemDelegate

use of com.facebook.buck.io.ProjectFilesystemDelegate in project buck by facebook.

the class AutoSparseIntegrationTest method testSymlinkNotExisting.

@Test
public void testSymlinkNotExisting() {
    ProjectFilesystemDelegate delegate = createDelegate();
    Assume.assumeFalse(delegate.isSymlink(repoPath.resolve("nonsuch")));
}
Also used : ProjectFilesystemDelegate(com.facebook.buck.io.ProjectFilesystemDelegate) Test(org.junit.Test)

Example 4 with ProjectFilesystemDelegate

use of com.facebook.buck.io.ProjectFilesystemDelegate in project buck by facebook.

the class AutoSparseIntegrationTest method testNotExists.

@Test
public void testNotExists() {
    ProjectFilesystemDelegate delegate = createDelegate();
    Assume.assumeFalse(delegate.exists(repoPath.resolve("nonsuch")));
}
Also used : ProjectFilesystemDelegate(com.facebook.buck.io.ProjectFilesystemDelegate) Test(org.junit.Test)

Example 5 with ProjectFilesystemDelegate

use of com.facebook.buck.io.ProjectFilesystemDelegate in project buck by facebook.

the class AutoSparseIntegrationTest method testAutosparseDisabled.

@Test
public void testAutosparseDisabled() {
    ProjectFilesystemDelegate delegate = createDelegate(repoPath, false, ImmutableList.of());
    Assume.assumeFalse(delegate instanceof AutoSparseProjectFilesystemDelegate);
}
Also used : ProjectFilesystemDelegate(com.facebook.buck.io.ProjectFilesystemDelegate) Test(org.junit.Test)

Aggregations

ProjectFilesystemDelegate (com.facebook.buck.io.ProjectFilesystemDelegate)19 Test (org.junit.Test)19 Path (java.nio.file.Path)6 DefaultProjectFilesystemDelegate (com.facebook.buck.io.DefaultProjectFilesystemDelegate)5 FileSystem (java.nio.file.FileSystem)5 EdenError (com.facebook.eden.thrift.EdenError)2 FakeClock (com.facebook.buck.timing.FakeClock)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1