From 9f8e1a8c8bc5175e22f6f2c634b372876f62ceac Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Mon, 13 Oct 2025 21:18:48 -0500 Subject: [PATCH] mcopy: info log files that are copied/downloaded --- .../itzg/helpers/sync/MulitCopyCommand.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/me/itzg/helpers/sync/MulitCopyCommand.java b/src/main/java/me/itzg/helpers/sync/MulitCopyCommand.java index 2f31534c..bd556579 100644 --- a/src/main/java/me/itzg/helpers/sync/MulitCopyCommand.java +++ b/src/main/java/me/itzg/helpers/sync/MulitCopyCommand.java @@ -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; @@ -39,6 +40,7 @@ + "Supports auto-detected sourcing from file list, directories, and URLs") @Slf4j public class MulitCopyCommand implements Callable { + @SuppressWarnings("unused") @Option(names = {"--help", "-h"}, usageHelp = true) boolean showHelp; @@ -154,7 +156,7 @@ private Publisher 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)) { @@ -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) { @@ -279,17 +277,15 @@ private Mono 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; } }) @@ -300,6 +296,10 @@ private Mono processRemoteSource(String source, Path destination) { .checkpoint("Retrieving " + source, true); } + private LoggingEventBuilder forSkipped() { + return log.atLevel(quietWhenSkipped ? Level.DEBUG : Level.INFO); + } + private Flux processRemoteListingFile(String source, Path destination) { @SuppressWarnings("resource") // closed on terminate SharedFetch sharedFetch = Fetch.sharedFetch("mcopy", SharedFetch.Options.builder().build());