Skip to content

Commit e4cee86

Browse files
committed
feat: 文件解析如果不是相对路径进行转换
1 parent 5bd0fbe commit e4cee86

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

core/src/main/kotlin/io/github/shoaky/sourcedownloader/core/processor/SourceProcessor.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,13 @@ class SourceProcessor(
270270
val fileContents = resolvedFiles.groupBy {
271271
options.matchFileOption(it)
272272
}.flatMap { (fileOption, files) ->
273-
val fileVariables = variableProvider.fileVariables(sourceItem, itemVariables, files)
274-
checkFileVariables(files, fileVariables)
275-
files.mapIndexed { index, file ->
273+
val relativizeFiles = files.map {
274+
it.takeIf { it.path.isAbsolute.not() }
275+
?: it.copy(path = downloadPath.relativize(it.path))
276+
}
277+
val fileVariables = variableProvider.fileVariables(sourceItem, itemVariables, relativizeFiles)
278+
checkFileVariables(relativizeFiles, fileVariables)
279+
relativizeFiles.mapIndexed { index, file ->
276280
val rawFileContent = RawFileContent(
277281
sourceSavePath,
278282
downloadPath,

core/src/test/kotlin/io/github/shoaky/sourcedownloader/core/YamlConfigOperatorTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ processors:
7474
ComponentId("test"),
7575
ComponentId("test"),
7676
ComponentId("test"),
77-
"",
77+
"./",
7878
options = ProcessorConfig.Options(
7979
renameTaskInterval = Duration.ofSeconds(100L)
8080
)

core/src/test/resources/config-test2.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ processors:
1313
source: "test"
1414
item-file-resolver: "test"
1515
downloader: "test"
16-
variable-providers:
17-
- "test"
1816
file-mover: "test"
1917
save-path: "test-path"
2018
options:

0 commit comments

Comments
 (0)