Skip to content

Commit

Permalink
fix liujingxing#45 修复当目标目录为原始目录的子目录时,任务执行后,目标目录不存在问题
Browse files Browse the repository at this point in the history
  • Loading branch information
liujingxing committed Jul 5, 2023
1 parent 2e03257 commit 1befb12
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions plugin/src/main/java/com/xml/guard/tasks/MoveDirTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,31 @@ open class MoveDirTask @Inject constructor(
}
val oldRelativePath = oldPath.replace(".", File.separator)
val newRelativePath = newPath.replace(".", File.separator)
val toFile = File(oldDir.absolutePath.replace(oldRelativePath, newRelativePath))
copy {
it.from(oldDir)
it.into(toFile)
oldDir.allFiles().forEach {
val toPath = it.absolutePath.replace(
"${File.separator}$oldRelativePath${File.separator}",
"${File.separator}$newRelativePath${File.separator}"
)
val toFilename = File(toPath)
if (!toFilename.exists()) toFilename.parentFile.mkdirs()
it.renameTo(toFilename)
}
delete(oldDir)
}
}
}

private fun File.allFiles(): List<File> {
val files = mutableListOf<File>()
listFiles()?.forEach {
if (it.isDirectory) {
files.addAll(it.allFiles())
} else {
files.add(it)
}
}
return files
}

private fun File.replaceText(map: Map<String, String>, manifestPackage: String?) {
var replaceText = readText()
map.forEach { (oldPath, newPath) ->
Expand Down

0 comments on commit 1befb12

Please sign in to comment.