use of com.google.copybara.util.FileUtil.ResolvedSymlink in project copybara by google.
the class CheckoutPath method readSymbolicLink.
@StarlarkMethod(name = "read_symlink", doc = "Read the symlink")
public CheckoutPath readSymbolicLink() throws EvalException {
try {
Path symlinkPath = checkoutDir.resolve(path);
if (!Files.isSymbolicLink(symlinkPath)) {
throw Starlark.errorf("%s is not a symlink", path);
}
ResolvedSymlink resolvedSymlink = FileUtil.resolveSymlink(Glob.ALL_FILES.relativeTo(checkoutDir), symlinkPath);
if (!resolvedSymlink.isAllUnderRoot()) {
throw Starlark.errorf("Symlink %s points to a file outside the checkout dir: %s", symlinkPath, resolvedSymlink.getRegularFile());
}
return create(checkoutDir.relativize(resolvedSymlink.getRegularFile()));
} catch (IOException e) {
String msg = String.format("Cannot resolve symlink %s: %s", path, e);
logger.atSevere().withCause(e).log("%s", msg);
throw Starlark.errorf("%s", msg);
}
}
Aggregations