Search in sources :

Example 1 with DefaultProjectFilesystemDelegate

use of com.facebook.buck.io.DefaultProjectFilesystemDelegate 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 DefaultProjectFilesystemDelegate

use of com.facebook.buck.io.DefaultProjectFilesystemDelegate 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 DefaultProjectFilesystemDelegate

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

the class EdenProjectFilesystemDelegateTest method computeSha1ForOrdinaryFileUnderMount.

@Test
public void computeSha1ForOrdinaryFileUnderMount() throws IOException, EdenError, TException {
    FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
    Path root = fs.getPath(JIMFS_WORKING_DIRECTORY);
    ProjectFilesystemDelegate delegate = new DefaultProjectFilesystemDelegate(root);
    EdenMount mount = createMock(EdenMount.class);
    Path path = fs.getPath("foo/bar");
    expect(mount.getBindMounts()).andReturn(ImmutableList.of());
    expect(mount.getPathRelativeToProjectRoot(root.resolve(path))).andReturn(Optional.of(path));
    expect(mount.getSha1(path)).andReturn(DUMMY_SHA1);
    replay(mount);
    EdenProjectFilesystemDelegate edenDelegate = new EdenProjectFilesystemDelegate(mount, delegate);
    assertEquals(DUMMY_SHA1, edenDelegate.computeSha1(path));
    verify(mount);
}
Also used : Path(java.nio.file.Path) 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 4 with DefaultProjectFilesystemDelegate

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

the class EdenProjectFilesystemDelegateTest method computeSha1ForOrdinaryFileUnderMountButBehindBindMount.

@Test
public void computeSha1ForOrdinaryFileUnderMountButBehindBindMount() throws IOException, EdenError, TException {
    FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
    Path root = fs.getPath(JIMFS_WORKING_DIRECTORY);
    ProjectFilesystemDelegate delegate = new DefaultProjectFilesystemDelegate(root);
    EdenMount mount = createMock(EdenMount.class);
    Path path = fs.getPath("buck-out/gen/some-output");
    Files.createDirectories(path.getParent());
    Files.createFile(path);
    byte[] bytes = new byte[] { 66, 85, 67, 75 };
    Files.write(path, bytes);
    expect(mount.getBindMounts()).andReturn(ImmutableList.of(fs.getPath("buck-out")));
    expect(mount.getPathRelativeToProjectRoot(root.resolve(path))).andReturn(Optional.of(path));
    replay(mount);
    EdenProjectFilesystemDelegate edenDelegate = new EdenProjectFilesystemDelegate(mount, delegate);
    assertEquals("EdenProjectFilesystemDelegate.computeSha1() should compute the SHA-1 directly via " + "DefaultProjectFilesystemDelegate because the path is behind a bind mount.", Sha1HashCode.fromHashCode(Hashing.sha1().hashBytes(bytes)), edenDelegate.computeSha1(path));
    verify(mount);
}
Also used : Path(java.nio.file.Path) 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 DefaultProjectFilesystemDelegate

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

the class EdenProjectFilesystemDelegateTest method computeSha1ForOrdinaryFileOutsideMount.

@Test
public void computeSha1ForOrdinaryFileOutsideMount() throws IOException {
    FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
    Path root = fs.getPath(JIMFS_WORKING_DIRECTORY);
    ProjectFilesystemDelegate delegate = new DefaultProjectFilesystemDelegate(root);
    Path target = fs.getPath("/example");
    Files.createFile(target);
    byte[] bytes = new byte[] { 66, 85, 67, 75 };
    Files.write(target, bytes);
    EdenMount mount = createMock(EdenMount.class);
    expect(mount.getBindMounts()).andReturn(ImmutableList.of());
    expect(mount.getPathRelativeToProjectRoot(target)).andReturn(Optional.empty());
    replay(mount);
    EdenProjectFilesystemDelegate edenDelegate = new EdenProjectFilesystemDelegate(mount, delegate);
    assertEquals("EdenProjectFilesystemDelegate.computeSha1() should return the SHA-1 of a file that is " + "outside of the EdenFS root.", Sha1HashCode.fromHashCode(Hashing.sha1().hashBytes(bytes)), edenDelegate.computeSha1(target));
    verify(mount);
}
Also used : Path(java.nio.file.Path) 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

DefaultProjectFilesystemDelegate (com.facebook.buck.io.DefaultProjectFilesystemDelegate)5 ProjectFilesystemDelegate (com.facebook.buck.io.ProjectFilesystemDelegate)5 FileSystem (java.nio.file.FileSystem)5 Path (java.nio.file.Path)5 Test (org.junit.Test)5 EdenError (com.facebook.eden.thrift.EdenError)2