diff --git a/src/core/installation.cpp b/src/core/installation.cpp --- a/src/core/installation.cpp +++ b/src/core/installation.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -357,18 +358,20 @@ porting, but will make many kde4 ksnsrc files work out of the box*/ //wallpaper is already managed in the case of !xdgTargetDirectory.isEmpty() if (!standardResourceDirectory.isEmpty() && standardResourceDirectory != QLatin1String("wallpaper")) { - QStandardPaths::StandardLocation location = QStandardPaths::TempLocation; - //crude translation KStandardDirs names -> QStandardPaths enum - if (standardResourceDirectory == QLatin1String("tmp")) { - location = QStandardPaths::TempLocation; - } else if (standardResourceDirectory == QLatin1String("config")) { - location = QStandardPaths::ConfigLocation; - } - if (scope == ScopeUser) { - installdir = QStandardPaths::writableLocation(location); - } else { // system scope - installdir = QStandardPaths::standardLocations(location).constLast(); + if (standardResourceDirectory == QLatin1String("config")) { + if (scope == ScopeUser) { + installdir = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation); + } else { // system scope + installdir = QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).constLast(); + } + } else { + // no need for separate handling for system scope in case of tmp folder + // TODO: ideally we would clean-up after ourselves, once the installation post processing is done + // the responsilbility for that is yet to be defined, and would also include this temporary dir + QTemporaryDir tempDir(QDir::tempPath() + QLatin1String("/kns-XXXXXX")); + tempDir.setAutoRemove(false); + installdir = tempDir.path(); } pathcounter++; } @@ -533,8 +536,9 @@ bool success = true; const bool update = ((entry.status() == KNS3::Entry::Updateable) || (entry.status() == KNS3::Entry::Updating)); - if (QFile::exists(installpath) && QDir::tempPath() != installdir) { - if (!update) { + if (QFile::exists(installpath)) { + // always remove in case it's already present and in a temporary directory, as it's just intermediate storage + if (!update && !installdir.startsWith(QDir::tempPath())) { Question question(Question::ContinueCancelQuestion); question.setQuestion(i18n("Overwrite existing file?") + QStringLiteral("\n'") + installpath + QLatin1Char('\'')); question.setTitle(i18n("Download File")); @@ -545,10 +549,6 @@ success = QFile::remove(installpath); } if (success) { - //remove in case it's already present and in a temporary directory, so we get to actually use the path again - if (installpath.startsWith(QDir::tempPath())) { - file.remove(installpath); - } success = file.rename(installpath); qCDebug(KNEWSTUFFCORE) << "move: " << file.fileName() << " to " << installpath; }