File tree Expand file tree Collapse file tree 4 files changed +20
-6
lines changed
plugin/src/main/kotlin/dev/vyp/stringcare/plugin Expand file tree Collapse file tree 4 files changed +20
-6
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import dev.vyp.stringcare.plugin.StringCareConfiguration
44import org.gradle.api.provider.Property
55import org.gradle.api.services.BuildService
66import org.gradle.api.services.BuildServiceParameters
7+ import java.io.File
78import java.util.UUID
89import 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 (
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments