summaryrefslogtreecommitdiffstats
path: root/depends/util/src
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-04-07 18:16:02 +0200
committerPetr Mrázek <peterix@gmail.com>2015-04-13 00:06:31 +0200
commit0220fe4f9d7f07fa137a11597b3465c76cfbcae3 (patch)
treee803758112d4dec1ed56929e517e88595616b3e7 /depends/util/src
parent58840ac10cc7aac866d61cbcece3c3b9be1af8b4 (diff)
downloadMultiMC-0220fe4f9d7f07fa137a11597b3465c76cfbcae3.tar
MultiMC-0220fe4f9d7f07fa137a11597b3465c76cfbcae3.tar.gz
MultiMC-0220fe4f9d7f07fa137a11597b3465c76cfbcae3.tar.lz
MultiMC-0220fe4f9d7f07fa137a11597b3465c76cfbcae3.tar.xz
MultiMC-0220fe4f9d7f07fa137a11597b3465c76cfbcae3.zip
GH-228 do not follow symlinks during instance copy on unix
Windows will need a more complex solution.
Diffstat (limited to 'depends/util/src')
-rw-r--r--depends/util/src/pathutils.cpp40
1 files changed, 30 insertions, 10 deletions
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)