summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Holzammer <andreas.holzammer.qnx@kdab.com>2012-10-08 14:21:15 +0200
committerTim Jenssen <tim.jenssen@digia.com>2012-10-08 15:20:52 +0200
commit149c4e166654896ca186a5df3d9e5a24a44544f8 (patch)
treefdd64f2224c124224f02a896e06831876f9c619d
parent2a6b5e4e7d7d7495d3c3ec4e16223d98d28ce103 (diff)
Add optional overwrite parameter to CopyDirectory operation
Change-Id: I9228805e179403fe1ac1be9390947223880a67eb Reviewed-by: Frank Osterfeld <frank.osterfeld@kdab.com> Reviewed-by: Tim Jenssen <tim.jenssen@digia.com>
-rw-r--r--src/libs/installer/copydirectoryoperation.cpp32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/libs/installer/copydirectoryoperation.cpp b/src/libs/installer/copydirectoryoperation.cpp
index f5e7692f5..dabc7fa62 100644
--- a/src/libs/installer/copydirectoryoperation.cpp
+++ b/src/libs/installer/copydirectoryoperation.cpp
@@ -65,14 +65,26 @@ void CopyDirectoryOperation::backup()
bool CopyDirectoryOperation::performOperation()
{
const QStringList args = arguments();
- if (args.count() != 2) {
+ if (args.count() < 2 || args.count() > 3) {
setError(InvalidArguments);
- setErrorString(tr("Invalid arguments in %0: %1 arguments given, 2 expected.").arg(name())
+ setErrorString(tr("Invalid arguments in %0: %1 arguments given, expected: <source> <target> [overwrite]").arg(name())
.arg(args.count()));
return false;
}
const QString sourcePath = args.at(0);
const QString targetPath = args.at(1);
+ bool overwrite = false;
+
+ if (args.count() > 2) {
+ const QString overwriteStr = args.at(2);
+ if (overwriteStr == QLatin1String("forceOverwrite")) {
+ overwrite = true;
+ } else {
+ setError(InvalidArguments);
+ setErrorString(tr("Invalid argument in %0: Third argument needs to be forceOverwrite, if specified").arg(name()));
+ return false;
+ }
+ }
const QFileInfo sourceInfo(sourcePath);
const QFileInfo targetInfo(targetPath);
@@ -115,10 +127,18 @@ bool CopyDirectoryOperation::performOperation()
return false;
}
} else {
- 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)));
+ const QString absolutePath = targetDir.absoluteFilePath(relativePath);
+ if (overwrite && QFile::exists(absolutePath) && !deleteFileNowOrLater(absolutePath)) {
+ setError(UserDefinedError);
+ setErrorString(tr("Failed to overwrite %1").arg(absolutePath));
+ return false;
+ }
+ QFile file(sourceDir.absoluteFilePath(itemName));
+ if (!file.copy(absolutePath)) {
+ setError(UserDefinedError);
+ setErrorString(tr("Could not copy %0 to %1, error was: %3").arg(sourceDir.absoluteFilePath(itemName),
+ targetDir.absoluteFilePath(relativePath),
+ file.errorString()));
return false;
}
autoPush.m_files.prepend(targetDir.absoluteFilePath(relativePath));