diff --git a/src/fileutils.cpp b/src/fileutils.cpp
index cefa41f747062f452f50480f594346c2ec190962..5a37dc307d258c9c2bee3ab9a82519bb3644707f 100644
--- a/src/fileutils.cpp
+++ b/src/fileutils.cpp
@@ -195,6 +195,14 @@ createHardlink(const std::filesystem::path& linkFile, const std::filesystem::pat
 bool
 createFileLink(const std::filesystem::path& linkFile, const std::filesystem::path& target, bool hard)
 {
+    if (linkFile == target)
+        return true;
+    std::error_code ec;
+    if (std::filesystem::exists(linkFile, ec)) {
+        if (std::filesystem::is_symlink(linkFile, ec) && std::filesystem::read_symlink(linkFile, ec) == target)
+            return true;
+        std::filesystem::remove(linkFile, ec);
+    }
     if (not hard or not createHardlink(linkFile, target))
         return createSymlink(linkFile, target);
     return true;