summaryrefslogtreecommitdiffstats
path: root/qmake/main.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2017-03-01 12:41:48 +0100
committerSimon Hausmann <simon.hausmann@qt.io>2017-05-02 10:27:15 +0000
commitc12b96daf2195c475c086f8f9be833aa0e28b26c (patch)
treed5a85c3935d63f7663fc0e55c804e932e2063b40 /qmake/main.cpp
parent7eae7e8103c79c9e098fc112bb8157971117678d (diff)
Preserve last modification timestamps of installed directories
Similar to the two parent commits, this patchs preserves the time stamps of files we install as a result of recursive directory copying. Change-Id: Id5931a467196d5cd67acfa0deffc2488af8a3669 Task-number: QTBUG-59004 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Diffstat (limited to 'qmake/main.cpp')
-rw-r--r--qmake/main.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/qmake/main.cpp b/qmake/main.cpp
index cc72645b59..f25b128d03 100644
--- a/qmake/main.cpp
+++ b/qmake/main.cpp
@@ -36,6 +36,7 @@
#include <qdebug.h>
#include <qregexp.h>
#include <qdir.h>
+#include <qdiriterator.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
@@ -43,6 +44,11 @@
#include <sys/types.h>
#include <sys/stat.h>
+#if defined(Q_OS_UNIX)
+#include <errno.h>
+#include <unistd.h>
+#endif
+
#ifdef Q_OS_WIN
# include <qt_windows.h>
#endif
@@ -267,6 +273,44 @@ static int installFile(const QString &source, const QString &target, bool exe =
return 0;
}
+static int installDirectory(const QString &source, const QString &target)
+{
+ QFileInfo fi(source);
+ if (false) {
+#if defined(Q_OS_UNIX)
+ } else if (fi.isSymLink()) {
+ QString linkTarget;
+ if (!IoUtils::readLinkTarget(fi.absoluteFilePath(), &linkTarget)) {
+ fprintf(stderr, "Could not read link %s: %s\n", qPrintable(fi.absoluteFilePath()), strerror(errno));
+ return 3;
+ }
+ QFile::remove(target);
+ if (::symlink(linkTarget.toLocal8Bit().constData(), target.toLocal8Bit().constData()) < 0) {
+ fprintf(stderr, "Could not create link: %s\n", strerror(errno));
+ return 3;
+ }
+#endif
+ } else if (fi.isDir()) {
+ QDir::current().mkpath(target);
+
+ QDirIterator it(source, QDir::AllEntries | QDir::NoDotAndDotDot);
+ while (it.hasNext()) {
+ it.next();
+ const QFileInfo &entry = it.fileInfo();
+ const QString &entryTarget = target + QDir::separator() + entry.fileName();
+
+ const int recursionResult = installDirectory(entry.filePath(), entryTarget);
+ if (recursionResult != 0)
+ return recursionResult;
+ }
+ } else {
+ const int fileCopyResult = installFile(source, target);
+ if (fileCopyResult != 0)
+ return fileCopyResult;
+ }
+ return 0;
+}
+
static int doQInstall(int argc, char **argv)
{
if (argc != 3) {
@@ -281,6 +325,8 @@ static int doQInstall(int argc, char **argv)
return installFile(source, target);
if (!strcmp(argv[0], "program"))
return installFile(source, target, /*exe=*/true);
+ if (!strcmp(argv[0], "directory"))
+ return installDirectory(source, target);
fprintf(stderr, "Error: Unsupported qinstall command type %s\n", argv[0]);
return 3;