From f7855afc3e4f21e4580e824ab98df191431af080 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Mon, 16 Dec 2024 02:36:20 +0100 Subject: [PATCH] Add symbolic link and void file handling --- .../staropensource/engine/base/utility/FileAccess.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/base/src/main/kotlin/de/staropensource/engine/base/utility/FileAccess.kt b/base/src/main/kotlin/de/staropensource/engine/base/utility/FileAccess.kt index 5ad6fd6da..7eb716acd 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/utility/FileAccess.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/utility/FileAccess.kt @@ -690,6 +690,13 @@ class FileAccess { * If nothing exists at this location, * then nothing will be done. * + * If a symbolic link exists at this + * location, then the just symbolic link + * will be deleted, not the file or + * directory it's pointing to. To delete + * the target too, use [getLinkDestination] + * before calling this method. + * * @return this instance * @throws IOAccessException on IO error * @since v1-alpha10 @@ -700,10 +707,11 @@ class FileAccess { try { logger.diag("Deleting '${unformatFromPath(path)}'") - if (file.isDirectory) + if (!isSymbolicLink() && file.isDirectory) Files.walkFileTree(path, DeleteDirectoryVisitor(path)) Files.delete(path) + } catch (_: NoSuchFileException) { } catch (exception: Exception) { throw IOAccessException("Unable to delete '${unformatFromPath(path)}'", exception) }