summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkh1 <qt-info@nokia.com>2011-06-08 14:58:52 +0200
committerkh1 <qt-info@nokia.com>2011-06-08 14:58:52 +0200
commit919c7a85ff92361c737b1a4a9bd089b3ea023c16 (patch)
tree75605c45ea73ad8e43cfdcfa3cc55d41b2917777
parente66b36f00943b97ef3a6cbbc07182c66145b6542 (diff)
parent8ea28002ec213d3baeefe0621265f6f0c95c4c34 (diff)
Merge branch 'master' into refactor
Conflicts: installerbuilder/libinstaller/copydirectoryoperation.cpp
-rw-r--r--installerbuilder/libinstaller/copydirectoryoperation.cpp219
-rw-r--r--installerbuilder/libinstaller/copydirectoryoperation.h21
2 files changed, 82 insertions, 158 deletions
diff --git a/installerbuilder/libinstaller/copydirectoryoperation.cpp b/installerbuilder/libinstaller/copydirectoryoperation.cpp
index ac01c9422..2159c4d43 100644
--- a/installerbuilder/libinstaller/copydirectoryoperation.cpp
+++ b/installerbuilder/libinstaller/copydirectoryoperation.cpp
@@ -32,17 +32,23 @@
**************************************************************************/
#include "copydirectoryoperation.h"
-#include <QFileInfo>
-#include <QDir>
-#include <QDirIterator>
-#include <QEventLoop>
-#include <QFutureWatcher>
-#include <QtConcurrentRun>
-
-#include <QDebug>
+#include <QtCore/QDir>
+#include <QtCore/QDirIterator>
+#include <QtCore/QFileInfo>
using namespace QInstaller;
+class AutoPush
+{
+public:
+ AutoPush(CopyDirectoryOperation *op)
+ : m_op(op) {}
+ ~AutoPush() { m_op->setValue(QLatin1String("files"), m_files); }
+
+ QStringList m_files;
+ CopyDirectoryOperation *m_op;
+};
+
/*
TRANSLATOR QInstaller::CopyDirectoryOperation
*/
@@ -56,163 +62,94 @@ CopyDirectoryOperation::~CopyDirectoryOperation()
{
}
-void CopyDirectoryOperation::letTheUiRunTillFinished(const QFuture<void> &future)
+void CopyDirectoryOperation::backup()
{
- if (!future.isFinished()) {
- QFutureWatcher<void> futureWatcher;
-
- QEventLoop loop;
- connect(&futureWatcher, SIGNAL(finished()), &loop, SLOT(quit()), Qt::QueuedConnection);
- futureWatcher.setFuture(future);
-
- if (!future.isFinished())
- loop.exec();
- }
- Q_ASSERT(future.isFinished());
}
-QList< QPair<QString,QString> > CopyDirectoryOperation::fileList()
+bool CopyDirectoryOperation::performOperation()
{
- Q_ASSERT(arguments().count() == 2);
- Q_ASSERT(!arguments().at(0).isEmpty());
- Q_ASSERT(!arguments().at(1).isEmpty());
- if (m_fileList.isEmpty()) {
- const QString sourcePath = arguments().at(0);
- const QString targetPath = arguments().at(1);
-
- m_fileList = generateFileList(sourcePath, targetPath);
+ const QStringList args = arguments();
+ if (args.count() != 2) {
+ setError(InvalidArguments);
+ setErrorString(tr("Invalid arguments in %0: %1 arguments given, 2 expected.").arg(name())
+ .arg(args.count()));
+ return false;
}
- return m_fileList;
-}
+ const QString sourcePath = args.at(0);
+ const QString targetPath = args.at(1);
-QList< QPair<QString,QString> > CopyDirectoryOperation::generateFileList(const QString &sourcePath, const QString &targetPath)
-{
- Q_ASSERT(QFileInfo(sourcePath).isDir());
- Q_ASSERT(!QFileInfo(targetPath).exists() || QFileInfo(targetPath).isDir());
- if (!QDir().mkpath(targetPath)) {
- qWarning() << QLatin1String("Could not create folder") << targetPath;
- } else {
- addDirectoryToDirectoryList(targetPath);
+ const QFileInfo sourceInfo(sourcePath);
+ const QFileInfo targetInfo(targetPath);
+ if (!sourceInfo.exists() || !sourceInfo.isDir() || !targetInfo.exists() || !targetInfo.isDir()) {
+ setError(InvalidArguments);
+ setErrorString(tr("Invalid arguments in %0: Directories are invalid: %1 %2").arg(name())
+ .arg(sourcePath).arg(targetPath));
+ return false;
}
+ const QDir sourceDir = sourceInfo.absoluteDir();
+ const QDir targetDir = targetInfo.absoluteDir();
- QDirIterator it(sourcePath, QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden | QDir::System);
+ AutoPush autoPush(this);
+ QDirIterator it(sourceInfo.absoluteFilePath(), QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden,
+ QDirIterator::Subdirectories);
while (it.hasNext()) {
- const QFileInfo currentFileInfo(it.next());
- if (currentFileInfo.isDir() && !currentFileInfo.isSymLink()) {
- generateFileList( currentFileInfo.absoluteFilePath(), QDir(targetPath).absoluteFilePath(currentFileInfo.fileName()));
- } else {
- const QString source = currentFileInfo.absoluteFilePath();
- const QString target = QDir(targetPath).absoluteFilePath(currentFileInfo.fileName());
- m_fileList.append(QPair<QString, QString>(source, target));
- }
- }
- return m_fileList;
-}
-
-bool CopyDirectoryOperation::copyFilesFromInternalFileList()
-{
- QList< QPair<QString, QString> > sourceDestinationFileList(fileList());
-
- QList< QPair<QString, QString> >::iterator i;
- for (i = sourceDestinationFileList.begin(); i != sourceDestinationFileList.end(); ++i) {
- QString source = (*i).first;
- QString dest = (*i).second;
-
- // If destination file exists, then we cannot use QFile::copy()
- // because it does not overwrite an existing file. So we remove
- // the destination file.
- if (QFile::exists(dest)) {
- QFile file(dest);
- if (!file.remove()) {
- setError(UserDefinedError);
- setErrorString(tr("Could not remove destination file %1: %2.").arg( dest, file.errorString()));
+ const QString itemName = it.next();
+ const QFileInfo itemInfo(sourceDir.absoluteFilePath(itemName));
+ const QString relativePath = sourceDir.relativeFilePath(itemName);
+ if (itemInfo.isSymLink()) {
+ // Check if symlink target is inside copied directory
+ const QString linkTarget = itemInfo.symLinkTarget();
+ if (linkTarget.startsWith(sourceDir.absolutePath())) {
+ // create symlink to copied location
+ const QString linkTargetRelative = sourceDir.relativeFilePath(linkTarget);
+ QFile(targetDir.absoluteFilePath(linkTargetRelative))
+ .link(targetDir.absoluteFilePath(relativePath));
+ } else {
+ // create symlink pointing to original location
+ QFile(linkTarget).link(targetDir.absoluteFilePath(relativePath));
+ }
+ // add file entry
+ autoPush.m_files.prepend(targetDir.absoluteFilePath(relativePath));
+ emit outputTextChanged(autoPush.m_files.first());
+ } else if (itemInfo.isDir()) {
+ if (!targetDir.mkpath(targetDir.absoluteFilePath(relativePath))) {
+ setError(InvalidArguments);
+ setErrorString(tr("Could not create %0").arg(targetDir.absoluteFilePath(relativePath)));
return false;
}
- }
-
- QFile file(source);
- const bool copied = file.copy(dest);
- if (!copied) {
- setError(UserDefinedError);
- setErrorString(tr("Could not copy %1 to %2: %3.").arg(source, dest, file.errorString()));
- return false;
} else {
- addFileToFileList(dest);
+ if (!QFile::copy(sourceDir.absoluteFilePath(itemName), targetDir.absoluteFilePath(relativePath))) {
+ setError(InvalidArguments);
+ setErrorString(tr("Could not copy %0 to %1").arg(sourceDir.absoluteFilePath(itemName))
+ .arg(targetDir.absoluteFilePath(relativePath)));
+ return false;
+ }
+ autoPush.m_files.prepend(targetDir.absoluteFilePath(relativePath));
+ emit outputTextChanged(autoPush.m_files.first());
}
}
return true;
}
-bool CopyDirectoryOperation::removeFilesFromInternalFileList()
-{
- const QStringList fileNameList = value(QLatin1String("files")).toStringList();
-
- bool result = true;
- foreach(const QString fileName, fileNameList) {
- result = result & deleteFileNowOrLater(fileName);
- }
-
- const QStringList directoryList = value(QLatin1String("directories")).toStringList();
-
- foreach(const QString directory, directoryList) {
- QDir().rmdir(directory);
- }
-
- return result;
-}
-
-void CopyDirectoryOperation::backup()
-{
-
-}
-bool CopyDirectoryOperation::performOperation()
-{
- const QStringList args = arguments();
- if (args.count() != 2) {
- setError(InvalidArguments);
- setErrorString(tr("Invalid arguments in %0: %1 arguments given, 2 expected.")
- .arg(name()).arg( args.count()));
- return false;
- }
-// const QString sourcePath = args.at(0);
-// const QString targetPath = args.at(1);
-
-
- typedef QList< QPair< QString, QString > > FileList;
- QFuture< FileList > fileListFuture = QtConcurrent::run(this, &CopyDirectoryOperation::fileList);
- letTheUiRunTillFinished(fileListFuture);
-
- QFuture< bool > allCopied = QtConcurrent::run(this, &CopyDirectoryOperation::copyFilesFromInternalFileList);
- letTheUiRunTillFinished(allCopied);
-
- return allCopied.result();
-}
-
bool CopyDirectoryOperation::undoOperation()
{
Q_ASSERT(arguments().count() == 2);
- QFuture<bool> allRemoved = QtConcurrent::run(this, &CopyDirectoryOperation::removeFilesFromInternalFileList);
- letTheUiRunTillFinished(allRemoved);
-
- return allRemoved.result();
-}
+ const QStringList files = value(QLatin1String("files")).toStringList();
+ foreach (const QString &file, files) {
+ if (!QFile::remove(file)) {
+ setError(InvalidArguments);
+ setErrorString(tr("Could not remove %0").arg(file));
+ return false;
+ }
+ QDir().rmpath(QFileInfo(file).absolutePath());
+ emit outputTextChanged(file);
+ }
-void CopyDirectoryOperation::addFileToFileList(const QString& fileName)
-{
- QStringList files = value(QLatin1String("files")).toStringList();
- files.push_front(fileName);
- setValue(QLatin1String("files"), files);
- emit outputTextChanged(fileName);
-}
+ setValue(QLatin1String("files"), QStringList());
-void CopyDirectoryOperation::addDirectoryToDirectoryList(const QString& directory)
-{
- QStringList directories = value(QLatin1String("directories")).toStringList();
- directories.push_front(directory);
- setValue( QLatin1String("directories"), directories);
- emit outputTextChanged(directory);
+ return true;
}
bool CopyDirectoryOperation::testOperation()
diff --git a/installerbuilder/libinstaller/copydirectoryoperation.h b/installerbuilder/libinstaller/copydirectoryoperation.h
index ad31207a1..f5db813e6 100644
--- a/installerbuilder/libinstaller/copydirectoryoperation.h
+++ b/installerbuilder/libinstaller/copydirectoryoperation.h
@@ -26,11 +26,11 @@
#ifndef COPYDIRECTORYOPERATION_H
#define COPYDIRECTORYOPERATION_H
+#include "installer_global.h"
+
#include <KDUpdater/UpdateOperation>
-#include "installer_global.h"
#include <QtCore/QObject>
-#include <QFuture>
namespace QInstaller {
@@ -39,7 +39,6 @@ class INSTALLER_EXPORT CopyDirectoryOperation : public QObject, public KDUpdater
{
Q_OBJECT
- friend class WorkerThread;
public:
CopyDirectoryOperation();
~CopyDirectoryOperation();
@@ -48,23 +47,11 @@ public:
bool performOperation();
bool undoOperation();
bool testOperation();
- CopyDirectoryOperation* clone() const;
+ CopyDirectoryOperation *clone() const;
Q_SIGNALS:
- void outputTextChanged( const QString& progress );
//TODO: needs progress signal
-
-private Q_SLOTS:
-
-private:
- void addFileToFileList( const QString& fileName );
- void addDirectoryToDirectoryList( const QString& directory );
- void letTheUiRunTillFinished(const QFuture<void> &_future);
- bool copyFilesFromInternalFileList();
- bool removeFilesFromInternalFileList();
- QList< QPair<QString,QString> > fileList();
- QList< QPair<QString,QString> > generateFileList(const QString &sourcePath, const QString &targetPath);
- QList< QPair<QString,QString> > m_fileList;
+ void outputTextChanged(const QString &progress);
};
}