Search in sources :

Example 1 with EdenError

use of com.facebook.eden.thrift.EdenError in project buck by facebook.

the class EdenProjectFilesystemDelegate method computeSha1.

private Sha1HashCode computeSha1(Path path, boolean retryWithRealPathIfEdenError) throws IOException {
    Preconditions.checkArgument(path.isAbsolute());
    Optional<Path> entry = mount.getPathRelativeToProjectRoot(path);
    if (entry.isPresent() && !isUnderBindMount(entry.get())) {
        try {
            return mount.getSha1(entry.get());
        } catch (TException e) {
            throw new IOException(e);
        } catch (EdenError e) {
            if (retryWithRealPathIfEdenError) {
                // It's possible that an EdenError was thrown because entry.get() was a path to a symlink,
                // which is not supported by Eden's getSha1() API. Try again if the real path is different
                // from the original path.
                Path realPath = path.toRealPath();
                if (!realPath.equals(path)) {
                    return computeSha1(realPath, /* retryWithRealPathIfEdenError */
                    false);
                }
            }
            throw new IOException(e);
        }
    }
    return delegate.computeSha1(path);
}
Also used : Path(java.nio.file.Path) TException(com.facebook.thrift.TException) EdenError(com.facebook.eden.thrift.EdenError) IOException(java.io.IOException)

Example 2 with EdenError

use of com.facebook.eden.thrift.EdenError 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 3 with EdenError

use of com.facebook.eden.thrift.EdenError 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 4 with EdenError

use of com.facebook.eden.thrift.EdenError in project buck by facebook.

the class Main method run.

private static int run(String... args) {
    Args argsObject = new Args();
    CmdLineParser parser = new CmdLineParser(argsObject);
    try {
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        e.printStackTrace();
        return 1;
    }
    try {
        return argsObject.run();
    } catch (EdenError | IOException | TException e) {
        e.printStackTrace();
        return 1;
    }
}
Also used : TException(com.facebook.thrift.TException) EdenError(com.facebook.eden.thrift.EdenError) CmdLineParser(org.kohsuke.args4j.CmdLineParser) IOException(java.io.IOException) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 5 with EdenError

use of com.facebook.eden.thrift.EdenError in project buck by facebook.

the class ProjectFilesystemDelegateFactory method newInstance.

/**
   * Must always create a new delegate for the specified {@code root}.
   */
public static ProjectFilesystemDelegate newInstance(Path root, String hgCmd, AutoSparseConfig autoSparseConfig) {
    Optional<EdenClient> client = tryToCreateEdenClient();
    if (client.isPresent()) {
        try {
            EdenMount mount = client.get().getMountFor(root);
            if (mount != null) {
                return new EdenProjectFilesystemDelegate(mount);
            }
        } catch (TException | EdenError e) {
            // If Eden is running but root is not a mount point, Eden getMountFor() should just return
            // null rather than throw an error.
            LOG.error(e, "Failed to find Eden client for %s.", root);
        }
    }
    if (autoSparseConfig.enabled()) {
        // We can't access BuckConfig because that class requires a
        // ProjectFileSystem, which we are in the process of building
        // Access the required info from the Config instead
        HgCmdLineInterface hgCmdLine = new HgCmdLineInterface(new PrintStreamProcessExecutorFactory(), root, hgCmd, ImmutableMap.of());
        AutoSparseState autoSparseState = AbstractAutoSparseFactory.getAutoSparseState(root, hgCmdLine, autoSparseConfig);
        if (autoSparseState != null) {
            LOG.debug("Autosparse enabled, using AutoSparseProjectFilesystemDelegate");
            return new AutoSparseProjectFilesystemDelegate(autoSparseState, root);
        }
    }
    // No Eden or Mercurial info available, use the default
    return new DefaultProjectFilesystemDelegate(root);
}
Also used : TException(com.facebook.thrift.TException) AutoSparseState(com.facebook.buck.util.autosparse.AutoSparseState) EdenClient(com.facebook.buck.eden.EdenClient) EdenMount(com.facebook.buck.eden.EdenMount) EdenError(com.facebook.eden.thrift.EdenError) PrintStreamProcessExecutorFactory(com.facebook.buck.util.PrintStreamProcessExecutorFactory) EdenProjectFilesystemDelegate(com.facebook.buck.eden.EdenProjectFilesystemDelegate) HgCmdLineInterface(com.facebook.buck.util.versioncontrol.HgCmdLineInterface) AutoSparseProjectFilesystemDelegate(com.facebook.buck.util.autosparse.AutoSparseProjectFilesystemDelegate)

Aggregations

EdenError (com.facebook.eden.thrift.EdenError)5 TException (com.facebook.thrift.TException)3 Path (java.nio.file.Path)3 DefaultProjectFilesystemDelegate (com.facebook.buck.io.DefaultProjectFilesystemDelegate)2 ProjectFilesystemDelegate (com.facebook.buck.io.ProjectFilesystemDelegate)2 IOException (java.io.IOException)2 FileSystem (java.nio.file.FileSystem)2 Test (org.junit.Test)2 EdenClient (com.facebook.buck.eden.EdenClient)1 EdenMount (com.facebook.buck.eden.EdenMount)1 EdenProjectFilesystemDelegate (com.facebook.buck.eden.EdenProjectFilesystemDelegate)1 PrintStreamProcessExecutorFactory (com.facebook.buck.util.PrintStreamProcessExecutorFactory)1 AutoSparseProjectFilesystemDelegate (com.facebook.buck.util.autosparse.AutoSparseProjectFilesystemDelegate)1 AutoSparseState (com.facebook.buck.util.autosparse.AutoSparseState)1 HgCmdLineInterface (com.facebook.buck.util.versioncontrol.HgCmdLineInterface)1 CmdLineException (org.kohsuke.args4j.CmdLineException)1 CmdLineParser (org.kohsuke.args4j.CmdLineParser)1