From d6fa34fd87da8b8abeaa19a76dc2cb7d37ba3c81 Mon Sep 17 00:00:00 2001 From: Jingwen Chen Date: Sun, 29 Apr 2018 12:38:48 -0400 Subject: [PATCH 1/2] Do not delete files in symlinks --- .../com/google/androidstudiopoet/writers/AbstractWriter.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/google/androidstudiopoet/writers/AbstractWriter.kt b/src/main/kotlin/com/google/androidstudiopoet/writers/AbstractWriter.kt index 001a1bab..78104b7c 100644 --- a/src/main/kotlin/com/google/androidstudiopoet/writers/AbstractWriter.kt +++ b/src/main/kotlin/com/google/androidstudiopoet/writers/AbstractWriter.kt @@ -1,5 +1,6 @@ package com.google.androidstudiopoet.writers +import org.apache.commons.io.FileUtils import java.io.File interface AbstractWriter { @@ -14,7 +15,9 @@ interface AbstractWriter { fun delete(path: String) { val file = File(path) - file.listFiles()?.forEach { delete(it.absolutePath) } + if (file.isDirectory && !FileUtils.isSymlink(file)) { + file.listFiles()?.forEach { delete(it.absolutePath) } + } file.delete() } } \ No newline at end of file From 764887a82e7e982a35d35ec7aa55ca4f5b18605b Mon Sep 17 00:00:00 2001 From: Jingwen Chen Date: Sun, 29 Apr 2018 12:57:45 -0400 Subject: [PATCH 2/2] No need for isDirectory() check during deletion --- .../com/google/androidstudiopoet/writers/AbstractWriter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/google/androidstudiopoet/writers/AbstractWriter.kt b/src/main/kotlin/com/google/androidstudiopoet/writers/AbstractWriter.kt index 78104b7c..b2ccc0e9 100644 --- a/src/main/kotlin/com/google/androidstudiopoet/writers/AbstractWriter.kt +++ b/src/main/kotlin/com/google/androidstudiopoet/writers/AbstractWriter.kt @@ -15,7 +15,7 @@ interface AbstractWriter { fun delete(path: String) { val file = File(path) - if (file.isDirectory && !FileUtils.isSymlink(file)) { + if (!FileUtils.isSymlink(file)) { file.listFiles()?.forEach { delete(it.absolutePath) } } file.delete()