Skip to content

Commit f0a0b9b

Browse files
committed
fix: Copy individual files correctly, add test for this case
1 parent f31a985 commit f0a0b9b

7 files changed

Lines changed: 20 additions & 8 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
kotlin.code.style=official
22
group=com.mineinabyss
3-
version=3.2.0-alpha.1
3+
version=3.2.0-alpha.2
44
idofrontVersion=0.25.6

keepup-api/src/main/kotlin/com/mineinabyss/keepup/config_sync/ConfigTreeBuilder.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.mineinabyss.keepup.config_sync
22

3+
import com.mineinabyss.keepup.helpers.MSG
4+
import com.mineinabyss.keepup.t
35
import java.nio.file.FileVisitResult
46
import java.nio.file.Path
57
import kotlin.io.path.*
@@ -14,12 +16,20 @@ class ConfigTreeBuilder {
1416
roots.forEach { copyPath ->
1517
val sourceRoot = configsRoot / copyPath.source
1618
val destOffset = Path(copyPath.dest)
17-
sourceRoot.walk(PathWalkOption.INCLUDE_DIRECTORIES)
18-
.filter { it.isRegularFile() }
19-
.forEach { source ->
20-
val dest = destOffset / source.relativeTo(sourceRoot)
21-
destToSource[dest] = source
19+
when {
20+
sourceRoot.isRegularFile() -> {
21+
val dest = destOffset / sourceRoot.fileName
22+
destToSource[dest] = sourceRoot
23+
return@forEach
2224
}
25+
sourceRoot.isDirectory() -> sourceRoot.walk(PathWalkOption.INCLUDE_DIRECTORIES)
26+
.filter { it.isRegularFile() }
27+
.forEach { source ->
28+
val dest = destOffset / source.relativeTo(sourceRoot)
29+
destToSource[dest] = source
30+
}
31+
else -> t.println("${MSG.warn} Included path $sourceRoot does not exist.")
32+
}
2333
}
2434
return destToSource
2535
}

keepup-api/src/test/resources/configs-source/feat/example/plugins/example/example2.yml renamed to keepup-api/src/test/resources/configs-source/should-copy-individual-files/copy-individual

File renamed without changes.

keepup-api/src/test/resources/configs-source/plugins/example/example1.yml renamed to keepup-api/src/test/resources/configs-source/should-correctly-default-dest/plugins/example/example2.yml

File renamed without changes.

keepup-api/src/test/resources/configs-source/should-correctly-set-dest/example1.yml

Whitespace-only changes.

keepup-api/src/test/resources/expected-output/plugins/example/copy-individual

Whitespace-only changes.

keepup-api/src/test/resources/inventory.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
feat/example:
22
copyPaths:
3-
- source: plugins/example
3+
- source: should-correctly-set-dest
4+
dest: plugins/example
5+
- should-correctly-default-dest
6+
- source: should-copy-individual-files/copy-individual
47
dest: plugins/example
5-
- feat/example
68

79
example-host:
810
include:

0 commit comments

Comments
 (0)