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);
}
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);
}
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);
}
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;
}
}
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);
}
Aggregations