From f0c43d7b53f833045e9f0d532cb3ff2f05ea6eb8 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Mon, 16 Dec 2024 02:36:55 +0100 Subject: [PATCH] Add 'noFollowSymbolicLink' argument to 'exists' --- .../de/staropensource/engine/base/utility/FileAccess.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 7eb716a..cf163c6 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 @@ -335,13 +335,17 @@ class FileAccess { /** * Returns if this file or directory exists. * + * @param noFollowSymbolicLink checks the symbolic link destination if `false`, checks the link itself if `true`. Has no effect if there doesn't exist a link at this location * @return exists? * @throws IOAccessException on IO error * @since v1-alpha10 */ @Throws(IOAccessException::class) - fun exists(): Boolean { - return Files.exists(path) + fun exists(noFollowSymbolicLink: Boolean = false): Boolean { + return if (noFollowSymbolicLink) + Files.exists(path, LinkOption.NOFOLLOW_LINKS) + else + Files.exists(path) } /**