Search in sources :

Example 1 with AbsoluteSymlinksNotAllowed

use of com.google.copybara.util.AbsoluteSymlinksNotAllowed in project copybara by google.

the class FolderOrigin method newReader.

@Override
public Reader<FolderRevision> newReader(Glob originFiles, Authoring authoring) throws ValidationException {
    return new Reader<FolderRevision>() {

        @Override
        public void checkout(FolderRevision ref, Path workdir) throws RepoException, ValidationException {
            try {
                FileUtil.copyFilesRecursively(ref.path, workdir, copySymlinkStrategy, originFiles);
                FileUtil.addPermissionsAllRecursively(workdir, FILE_PERMISSIONS);
            } catch (AbsoluteSymlinksNotAllowed e) {
                throw new ValidationException("Cannot copy files into the workdir: Some" + " symlinks refer to locations outside of the folder and" + " 'materialize_outside_symlinks' config option was not used:\n" + "  %s -> %s\n", e.getSymlink(), e.getDestinationFile());
            } catch (IOException e) {
                throw new RepoException(String.format("Cannot copy files into the workdir:\n" + "  origin folder: %s\n" + "  workdir: %s", ref.path, workdir), e);
            }
        }

        @Override
        public ChangesResponse<FolderRevision> changes(@Nullable FolderRevision fromRef, FolderRevision toRef) throws RepoException {
            // Ignore fromRef since a folder doesn't have history of changes
            return ChangesResponse.forChanges(ImmutableList.of(change(toRef)));
        }

        @Override
        public boolean supportsHistory() {
            return false;
        }

        @Override
        public Change<FolderRevision> change(FolderRevision ref) throws RepoException {
            return new Change<>(ref, author, message, ref.readTimestamp(), ImmutableMap.of());
        }

        @Override
        public void visitChanges(FolderRevision start, ChangesVisitor visitor) throws RepoException {
            visitor.visit(change(start));
        }
    };
}
Also used : Path(java.nio.file.Path) AbsoluteSymlinksNotAllowed(com.google.copybara.util.AbsoluteSymlinksNotAllowed) ValidationException(com.google.copybara.exception.ValidationException) IOException(java.io.IOException) RepoException(com.google.copybara.exception.RepoException) Change(com.google.copybara.Change) Nullable(javax.annotation.Nullable)

Aggregations

Change (com.google.copybara.Change)1 RepoException (com.google.copybara.exception.RepoException)1 ValidationException (com.google.copybara.exception.ValidationException)1 AbsoluteSymlinksNotAllowed (com.google.copybara.util.AbsoluteSymlinksNotAllowed)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Nullable (javax.annotation.Nullable)1