Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/main/java/me/itzg/helpers/sync/MulitCopyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.jetbrains.annotations.Blocking;
import org.reactivestreams.Publisher;
import org.slf4j.event.Level;
import org.slf4j.spi.LoggingEventBuilder;
import picocli.CommandLine.Command;
import picocli.CommandLine.ExitCode;
import picocli.CommandLine.Option;
Expand All @@ -39,6 +40,7 @@
+ "Supports auto-detected sourcing from file list, directories, and URLs")
@Slf4j
public class MulitCopyCommand implements Callable<Integer> {
@SuppressWarnings("unused")
@Option(names = {"--help", "-h"}, usageHelp = true)
boolean showHelp;

Expand Down Expand Up @@ -154,7 +156,7 @@ private Publisher<Path> processSource(String source, boolean fileIsListing, Path
} else {
final Path path = Paths.get(resolvedSource);
if (!Files.exists(path)) {
return Mono.error(new GenericException(String.format("Source file '%s' does not exist", resolvedSource)));
return Mono.error(new InvalidParameterException(String.format("Source file '%s' does not exist", resolvedSource)));
}

if (Files.isDirectory(path)) {
Expand Down Expand Up @@ -209,27 +211,23 @@ private Path processFileImmediate(Path source, Path scopedDest) {
try {
if (Files.size(source) != Files.size(destFile)) {
if (Files.getLastModifiedTime(source).compareTo(Files.getLastModifiedTime(destFile)) > 0) {
log.debug("Copying over existing={} file since source={} file is newer",
log.info("Copying over existing file {} since {} is newer",
destFile, source
);

Files.copy(source, destFile, StandardCopyOption.REPLACE_EXISTING);
} else {
log.debug("Skipping existing={} since it is newer than source={}",
destFile, source
);
forSkipped().log("Skipping existing={} since it is newer than source={}", destFile, source);
}
} else {
log.debug("Skipping existing={} since it has same size as source={}",
destFile, source
);
forSkipped().log("Skipping existing={} since it has same size as source={}", destFile, source);
}
} catch (IOException e) {
throw new GenericException("Failed to evaluate/copy existing file", e);
}
} else {
try {
log.debug("Copying new file from={} to={}", source, destFile);
log.info("Copying new file from {} to {}", source, destFile);

Files.copy(source, destFile);
} catch (IOException e) {
Expand Down Expand Up @@ -279,17 +277,15 @@ private Mono<Path> processRemoteSource(String source, Path destination) {
.handleStatus((status, uri, file) -> {
switch (status) {
case DOWNLOADING:
log.info("Downloading {} from {}", file, uri);
break;
case SKIP_FILE_UP_TO_DATE:
log.atLevel(quietWhenSkipped ? Level.DEBUG : Level.INFO)
.log("The file {} is already up to date", file);
forSkipped().log("The file {} is already up to date", file);
break;
case SKIP_FILE_EXISTS:
log.atLevel(quietWhenSkipped ? Level.DEBUG : Level.INFO)
.log("The file {} already exists", file);
forSkipped().log("The file {} already exists", file);
break;
case DOWNLOADED:
log.info("Downloaded {} from {}", file, uri);
break;
}
})
Expand All @@ -300,6 +296,10 @@ private Mono<Path> processRemoteSource(String source, Path destination) {
.checkpoint("Retrieving " + source, true);
}

private LoggingEventBuilder forSkipped() {
return log.atLevel(quietWhenSkipped ? Level.DEBUG : Level.INFO);
}

private Flux<Path> processRemoteListingFile(String source, Path destination) {
@SuppressWarnings("resource") // closed on terminate
SharedFetch sharedFetch = Fetch.sharedFetch("mcopy", SharedFetch.Options.builder().build());
Expand Down