summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--depends/util/include/pathutils.h2
-rw-r--r--depends/util/src/pathutils.cpp40
-rw-r--r--logic/InstanceList.cpp2
3 files changed, 32 insertions, 12 deletions
diff --git a/depends/util/include/pathutils.h b/depends/util/include/pathutils.h
index 2cc65db5..a506280e 100644
--- a/depends/util/include/pathutils.h
+++ b/depends/util/include/pathutils.h
@@ -51,7 +51,7 @@ LIBUTIL_EXPORT bool ensureFilePathExists(QString filenamepath);
*/
LIBUTIL_EXPORT bool ensureFolderPathExists(QString filenamepath);
-LIBUTIL_EXPORT bool copyPath(QString src, QString dst);
+LIBUTIL_EXPORT bool copyPath(QString src, QString dst, bool follow_symlinks = true);
/// Opens the given file in the default application.
LIBUTIL_EXPORT void openFileInDefaultProgram(QString filename);
diff --git a/depends/util/src/pathutils.cpp b/depends/util/src/pathutils.cpp
index a193212c..1cbb2cb2 100644
--- a/depends/util/src/pathutils.cpp
+++ b/depends/util/src/pathutils.cpp
@@ -19,6 +19,7 @@
#include <QDir>
#include <QDesktopServices>
#include <QUrl>
+#include <QDebug>
QString PathCombine(QString path1, QString path2)
{
@@ -111,26 +112,45 @@ bool ensureFolderPathExists(QString foldernamepath)
return success;
}
-bool copyPath(QString src, QString dst)
+bool copyPath(QString src, QString dst, bool follow_symlinks)
{
+ //NOTE always deep copy on windows. the alternatives are too messy.
+ #if defined Q_OS_WIN32
+ follow_symlinks = true;
+ #endif
+
QDir dir(src);
if (!dir.exists())
return false;
if (!ensureFolderPathExists(dst))
return false;
- foreach(QString d, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
- {
- QString inner_src = src + QDir::separator() + d;
- QString inner_dst = dst + QDir::separator() + d;
- copyPath(inner_src, inner_dst);
- }
+ bool OK = true;
- foreach(QString f, dir.entryList(QDir::Files))
+ foreach(QString f, dir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System))
{
- QFile::copy(src + QDir::separator() + f, dst + QDir::separator() + f);
+ QString inner_src = src + QDir::separator() + f;
+ QString inner_dst = dst + QDir::separator() + f;
+ QFileInfo fileInfo(inner_src);
+ if(!follow_symlinks && fileInfo.isSymLink())
+ {
+ OK &= QFile::link(fileInfo.symLinkTarget(),inner_dst);
+ }
+ else if (fileInfo.isDir())
+ {
+ OK &= copyPath(inner_src, inner_dst, follow_symlinks);
+ }
+ else if (fileInfo.isFile())
+ {
+ OK &= QFile::copy(inner_src, inner_dst);
+ }
+ else
+ {
+ OK = false;
+ qCritical() << "Copy ERROR: Unknown filesystem object:" << inner_src;
+ }
}
- return true;
+ return OK;
}
void openDirInDefaultProgram(QString path, bool ensureExists)
diff --git a/logic/InstanceList.cpp b/logic/InstanceList.cpp
index a65d9f56..4e295e7f 100644
--- a/logic/InstanceList.cpp
+++ b/logic/InstanceList.cpp
@@ -501,7 +501,7 @@ InstanceList::copyInstance(InstancePtr &newInstance, InstancePtr &oldInstance, c
QDir rootDir(instDir);
qDebug() << instDir.toUtf8();
- if (!copyPath(oldInstance->instanceRoot(), instDir))
+ if (!copyPath(oldInstance->instanceRoot(), instDir, false))
{
rootDir.removeRecursively();
return InstanceList::CantCreateDir;