From 097af11a6dce8b3e8b87058058cad5880a14e880 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 29 Nov 2017 17:03:42 +0200 Subject: [PATCH] Improvement. Fix broken symlink automatically. --HG-- branch : develop --- src/libs/vmisc/vcommonsettings.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/libs/vmisc/vcommonsettings.cpp b/src/libs/vmisc/vcommonsettings.cpp index 84f28267c..b43ed2650 100644 --- a/src/libs/vmisc/vcommonsettings.cpp +++ b/src/libs/vmisc/vcommonsettings.cpp @@ -150,7 +150,8 @@ void SymlinkCopyDirRecursive(const QString &fromDir, const QString &toDir, bool to = to + QLatin1String(".lnk"); #endif - if (QFile::exists(to)) + QFileInfo fileTo(to); + if (not fileTo.isSymLink() && fileTo.exists()) { if (replaceOnConflit) { @@ -161,6 +162,21 @@ void SymlinkCopyDirRecursive(const QString &fromDir, const QString &toDir, bool continue; } } + else if (fileTo.isSymLink()) + { + if (not fileTo.exists()) + { // automatically fix broken symlink + QFile::remove(to); + } + else if (replaceOnConflit) + { + QFile::remove(to); + } + else + { + continue; + } + } QFile::link(from, to); }