From c12b96daf2195c475c086f8f9be833aa0e28b26c Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 1 Mar 2017 12:41:48 +0100 Subject: 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 --- qmake/main.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'qmake/main.cpp') 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 #include #include +#include #include #include #include @@ -43,6 +44,11 @@ #include #include +#if defined(Q_OS_UNIX) +#include +#include +#endif + #ifdef Q_OS_WIN # include #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; -- cgit v1.2.3