Skip to content

Commit 7a205f0

Browse files
committed
Enhance file restoration logic and improve task output tracking: refactor restore method to ensure backup file validation, synchronize temporary folder deletion, and enforce task outputs to be always considered out-of-date for accurate rebuilds.
1 parent 5d2a3d4 commit 7a205f0

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

plugin/src/main/kotlin/dev/vyp/stringcare/plugin/internal/Extensions.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,19 @@ fun File.restore(
273273
projectPath: String,
274274
tempRoot: String,
275275
): File {
276-
val baseTemp = Path.of(tempRoot).toAbsolutePath().normalize()
277-
val current = this.toPath().toAbsolutePath().normalize()
278-
val relative = baseTemp.relativize(current)
279-
val restore = Path.of(projectPath).resolve(relative).normalize().toFile()
276+
val baseDir = File(tempRoot).canonicalFile
277+
val backupFile = this.canonicalFile
278+
val prefix = baseDir.absolutePath.let { if (it.endsWith(File.separator)) it else it + File.separator }
279+
require(backupFile.absolutePath.startsWith(prefix)) {
280+
"Backup ${backupFile.absolutePath} is not under temp root ${baseDir.absolutePath}"
281+
}
282+
val relative = backupFile.absolutePath.substring(prefix.length)
283+
val restore = File(projectPath, relative).normalize()
280284
withFileLock(restore) {
281285
if (restore.exists()) {
282286
restore.delete()
283287
}
284-
File(restore.absolutePath).writeText(this.getContent())
288+
File(restore.absolutePath).writeText(backupFile.getContent())
285289
}
286290
return restore
287291
}

plugin/src/main/kotlin/dev/vyp/stringcare/plugin/services/StringCareBuildService.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import dev.vyp.stringcare.plugin.StringCareConfiguration
44
import org.gradle.api.provider.Property
55
import org.gradle.api.services.BuildService
66
import org.gradle.api.services.BuildServiceParameters
7+
import java.io.File
78
import java.util.UUID
89
import java.util.concurrent.ConcurrentHashMap
910

@@ -37,7 +38,11 @@ abstract class StringCareBuildService : BuildService<StringCareBuildService.Para
3738
}
3839

3940
fun resetTempFolder() {
40-
tempDir = null
41+
synchronized(this) {
42+
val path = tempDir ?: return
43+
tempDir = null
44+
runCatching { File(path).deleteRecursively() }
45+
}
4146
}
4247

4348
fun putVariantApplicationId(

plugin/src/main/kotlin/dev/vyp/stringcare/plugin/tasks/RestoreAssetsTask.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ abstract class RestoreAssetsTask : DefaultTask() {
3737

3838
init {
3939
skip.convention(false)
40+
outputs.upToDateWhen { false }
4041
}
4142

4243
@TaskAction

plugin/src/main/kotlin/dev/vyp/stringcare/plugin/tasks/RestoreStringsTask.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ abstract class RestoreStringsTask : DefaultTask() {
3737

3838
init {
3939
skip.convention(false)
40+
// Restore rewrites sources under projectPath; Gradle has no tracked outputs here. Without this,
41+
// inputs (projectPath, moduleName) never change between builds so the task can be UP-TO-DATE
42+
// while sources remain obfuscated from the last ObfuscateStringsTask run.
43+
outputs.upToDateWhen { false }
4044
}
4145

4246
@TaskAction

0 commit comments

Comments
 (0)