Add symbolic link and void file handling

This commit is contained in:
JeremyStar™ 2024-12-16 02:36:20 +01:00
parent 6389aaa5d0
commit f7855afc3e
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D

View file

@ -690,6 +690,13 @@ class FileAccess {
* If nothing exists at this location, * If nothing exists at this location,
* then nothing will be done. * 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 * @return this instance
* @throws IOAccessException on IO error * @throws IOAccessException on IO error
* @since v1-alpha10 * @since v1-alpha10
@ -700,10 +707,11 @@ class FileAccess {
try { try {
logger.diag("Deleting '${unformatFromPath(path)}'") logger.diag("Deleting '${unformatFromPath(path)}'")
if (file.isDirectory) if (!isSymbolicLink() && file.isDirectory)
Files.walkFileTree(path, DeleteDirectoryVisitor(path)) Files.walkFileTree(path, DeleteDirectoryVisitor(path))
Files.delete(path) Files.delete(path)
} catch (_: NoSuchFileException) {
} catch (exception: Exception) { } catch (exception: Exception) {
throw IOAccessException("Unable to delete '${unformatFromPath(path)}'", exception) throw IOAccessException("Unable to delete '${unformatFromPath(path)}'", exception)
} }