Skip to content

Commit

Permalink
Merge pull request #369 from gdgib/G2-1560-CopyWalker
Browse files Browse the repository at this point in the history
G2-1560 CopyWalker upgrade - include filter
  • Loading branch information
gdgib authored Apr 29, 2024
2 parents bc937d0 + 726905e commit 4de13fc
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Set;

import com.g2forge.alexandria.java.function.IFunction1;
import com.g2forge.alexandria.java.function.IPredicate2;
import com.g2forge.alexandria.java.io.RuntimeIOException;

import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -84,6 +85,8 @@ public FileVisitResult postVisitDirectory(Path directorySource, IOException exce
public FileVisitResult preVisitDirectory(Path directorySource, BasicFileAttributes attributes) {
// Copy the directory before visiting it's children
final Path directoryTarget = getTarget(directorySource);
// Skip the subtree if it's not included
if (!getConfig().getInclude().test(directoryTarget, false)) return FileVisitResult.SKIP_SUBTREE;
final CopyOption[] options = getConfig().getOptions().apply(directoryTarget);
try {
Files.copy(directorySource, directoryTarget, HFile.optionFilter(options, o -> !(o instanceof ExtendedCopyOption)));
Expand All @@ -101,8 +104,10 @@ public FileVisitResult preVisitDirectory(Path directorySource, BasicFileAttribut
@Override
public FileVisitResult visitFile(Path fileSource, BasicFileAttributes attrs) {
final Path fileTarget = getTarget(fileSource);
final CopyOption[] options = getConfig().getOptions().apply(fileTarget);
copyFile(fileSource, fileTarget, options);
if (getConfig().getInclude().test(fileTarget, true)) {
final CopyOption[] options = getConfig().getOptions().apply(fileTarget);
copyFile(fileSource, fileTarget, options);
}
return FileVisitResult.CONTINUE;
}
}
Expand All @@ -112,6 +117,9 @@ public FileVisitResult visitFile(Path fileSource, BasicFileAttributes attrs) {
@Builder.Default
protected final IFunction1<? super Path, ? extends CopyOption[]> options = IFunction1.create(new CopyOption[] { StandardCopyOption.COPY_ATTRIBUTES });

@Builder.Default
protected final IPredicate2<? super Path, ? super Boolean> include = IPredicate2.create(true);

protected Visitor constructVisitor(Path start) {
return new Visitor(this, start);
}
Expand Down

0 comments on commit 4de13fc

Please sign in to comment.