Skip to content

Commit e291571

Browse files
authored
sync: skip missing source directories (#539)
1 parent aced9f9 commit e291571

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[![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)
22
[![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)
3+
![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)
34

45
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.
56

src/main/java/me/itzg/helpers/sync/SynchronizingFileVisitor.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,17 @@ static int walkDirectories(List<Path> srcDest, boolean skipNewerInDestination,
3030
final Path dest = srcDest.getLast();
3131

3232
for (final Path src : srcDest.subList(0, srcDest.size() - 1)) {
33-
try {
34-
Files.walkFileTree(src, new SynchronizingFileVisitor(src, dest, skipNewerInDestination, fileProcessor));
35-
} catch (IOException e) {
36-
log.error("Failed to sync and interpolate {} into {} : {}", src, dest, e.getMessage());
37-
log.debug("Details", e);
38-
return 1;
33+
if (Files.isDirectory(src)) {
34+
try {
35+
Files.walkFileTree(src, new SynchronizingFileVisitor(src, dest, skipNewerInDestination, fileProcessor));
36+
} catch (IOException e) {
37+
log.error("Failed to sync and interpolate {} into {} : {}", src, dest, e.getMessage());
38+
log.debug("Details", e);
39+
return 1;
40+
}
41+
}
42+
else {
43+
log.debug("Skipping missing source directory {}", src);
3944
}
4045
}
4146

src/test/java/me/itzg/helpers/sync/SyncAndInterpolateTest.java

+25
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,31 @@ void copiesFromTwoSrcCommaDelim(Class<?> commandClass, @TempDir Path tempDir) th
101101
assertThat(destDir.resolve("test4.txt")).exists();
102102
}
103103

104+
@ParameterizedTest
105+
@ValueSource(classes = {Sync.class, SyncAndInterpolate.class})
106+
void skipsMissingSrcDir(Class<?> commandClass, @TempDir Path tempDir) throws Exception {
107+
final Path srcDir1 = Files.createDirectory(tempDir.resolve("src"));
108+
Files.createFile(srcDir1.resolve("test1.txt"));
109+
Files.createFile(srcDir1.resolve("test2.txt"));
110+
final Path destDir = Files.createDirectory(tempDir.resolve("dest"));
111+
112+
final String stderr = tapSystemErr(() -> {
113+
final int exitCode = new CommandLine(commandClass)
114+
.execute(
115+
"--replace-env-file-suffixes=json",
116+
String.join(",", srcDir1.toString(), tempDir.resolve("missing").toString()),
117+
destDir.toString()
118+
);
119+
120+
assertThat(exitCode).isEqualTo(0);
121+
});
122+
assertThat(stderr).isBlank();
123+
124+
assertThat(destDir).isNotEmptyDirectory();
125+
assertThat(destDir.resolve("test1.txt")).exists();
126+
assertThat(destDir.resolve("test2.txt")).exists();
127+
}
128+
104129
}
105130

106131
}

0 commit comments

Comments
 (0)