Search in sources :

Example 1 with TException

use of com.facebook.thrift.TException 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 TException

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

use of com.facebook.thrift.TException 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)3 TException (com.facebook.thrift.TException)3 IOException (java.io.IOException)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 Path (java.nio.file.Path)1 CmdLineException (org.kohsuke.args4j.CmdLineException)1 CmdLineParser (org.kohsuke.args4j.CmdLineParser)1