diff --git a/README.md b/README.md index f2a7ea82..94727447 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/itzg/mc-image-helper?sort=semver)](https://github.com/itzg/mc-image-helper/releases/latest) [![test](https://github.com/itzg/mc-image-helper/actions/workflows/test.yml/badge.svg)](https://github.com/itzg/mc-image-helper/actions/workflows/test.yml) +![LOC](https://img.shields.io/endpoint?url=https%3A%2F%2Fshields-codetab-code-loc-bridge.vercel.app%2Fapi%2Fcodeloc%3Fgithub%3Ditzg%2Fmc-image-helper%26language%3Djava) This tool does the complicated bits for the [itzg/minecraft-server](https://github.com/itzg/docker-minecraft-server) and [itzg/bungeecord](https://github.com/itzg/docker-bungeecord/) Docker images. diff --git a/src/main/java/me/itzg/helpers/sync/SynchronizingFileVisitor.java b/src/main/java/me/itzg/helpers/sync/SynchronizingFileVisitor.java index 27ccb87d..5c777ae6 100644 --- a/src/main/java/me/itzg/helpers/sync/SynchronizingFileVisitor.java +++ b/src/main/java/me/itzg/helpers/sync/SynchronizingFileVisitor.java @@ -30,12 +30,17 @@ static int walkDirectories(List srcDest, boolean skipNewerInDestination, final Path dest = srcDest.getLast(); for (final Path src : srcDest.subList(0, srcDest.size() - 1)) { - try { - Files.walkFileTree(src, new SynchronizingFileVisitor(src, dest, skipNewerInDestination, fileProcessor)); - } catch (IOException e) { - log.error("Failed to sync and interpolate {} into {} : {}", src, dest, e.getMessage()); - log.debug("Details", e); - return 1; + if (Files.isDirectory(src)) { + try { + Files.walkFileTree(src, new SynchronizingFileVisitor(src, dest, skipNewerInDestination, fileProcessor)); + } catch (IOException e) { + log.error("Failed to sync and interpolate {} into {} : {}", src, dest, e.getMessage()); + log.debug("Details", e); + return 1; + } + } + else { + log.debug("Skipping missing source directory {}", src); } } diff --git a/src/test/java/me/itzg/helpers/sync/SyncAndInterpolateTest.java b/src/test/java/me/itzg/helpers/sync/SyncAndInterpolateTest.java index d778bd95..a5425822 100644 --- a/src/test/java/me/itzg/helpers/sync/SyncAndInterpolateTest.java +++ b/src/test/java/me/itzg/helpers/sync/SyncAndInterpolateTest.java @@ -101,6 +101,31 @@ void copiesFromTwoSrcCommaDelim(Class commandClass, @TempDir Path tempDir) th assertThat(destDir.resolve("test4.txt")).exists(); } + @ParameterizedTest + @ValueSource(classes = {Sync.class, SyncAndInterpolate.class}) + void skipsMissingSrcDir(Class commandClass, @TempDir Path tempDir) throws Exception { + final Path srcDir1 = Files.createDirectory(tempDir.resolve("src")); + Files.createFile(srcDir1.resolve("test1.txt")); + Files.createFile(srcDir1.resolve("test2.txt")); + final Path destDir = Files.createDirectory(tempDir.resolve("dest")); + + final String stderr = tapSystemErr(() -> { + final int exitCode = new CommandLine(commandClass) + .execute( + "--replace-env-file-suffixes=json", + String.join(",", srcDir1.toString(), tempDir.resolve("missing").toString()), + destDir.toString() + ); + + assertThat(exitCode).isEqualTo(0); + }); + assertThat(stderr).isBlank(); + + assertThat(destDir).isNotEmptyDirectory(); + assertThat(destDir.resolve("test1.txt")).exists(); + assertThat(destDir.resolve("test2.txt")).exists(); + } + } } \ No newline at end of file