ExternalStorage — remove all storage files

This commit is contained in:
Vladimir Krivosheev
2017-05-03 14:29:45 +02:00
parent 80ba4d8a64
commit 561e44b280
2 changed files with 7 additions and 0 deletions
@@ -121,6 +121,7 @@ private fun createStorage(project: Project): PersistentHashMap<String, ByteArray
})
fun deleteFileAndWriteLatestFormatVersion() {
dir.deleteChildrenStartingWith(file.fileName.toString())
file.delete()
versionFile.outputStream().use { it.write(MODULE_FILE_FORMAT_VERSION) }
@@ -98,6 +98,12 @@ fun Path.deleteWithParentsIfEmpty(root: Path, isFile: Boolean = true): Boolean {
return true
}
fun Path.deleteChildrenStartingWith(prefix: String) {
directoryStreamIfExists({ it.fileName.toString().startsWith(prefix) }) { it.toList() }?.forEach {
it.delete()
}
}
private fun Path.deleteRecursively() = Files.walkFileTree(this, object : SimpleFileVisitor<Path>() {
override fun visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult {
try {