Changeset View
Changeset View
Standalone View
Standalone View
src/core/installation.cpp
Show All 16 Lines | 1 | /* | |||
---|---|---|---|---|---|
17 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | 17 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "installation.h" | 20 | #include "installation.h" | ||
21 | 21 | | |||
22 | #include <QDir> | 22 | #include <QDir> | ||
23 | #include <QFile> | 23 | #include <QFile> | ||
24 | #include <QTemporaryFile> | 24 | #include <QTemporaryFile> | ||
25 | #include <QTemporaryDir> | ||||
25 | #include <QProcess> | 26 | #include <QProcess> | ||
26 | #include <QUrlQuery> | 27 | #include <QUrlQuery> | ||
27 | #include <QDesktopServices> | 28 | #include <QDesktopServices> | ||
28 | 29 | | |||
29 | #include "qmimedatabase.h" | 30 | #include "qmimedatabase.h" | ||
30 | #include "karchive.h" | 31 | #include "karchive.h" | ||
31 | #include "kzip.h" | 32 | #include "kzip.h" | ||
32 | #include "ktar.h" | 33 | #include "ktar.h" | ||
▲ Show 20 Lines • Show All 319 Lines • ▼ Show 20 Line(s) | 348 | if (!standardResourceDirectory.isEmpty()) { | |||
352 | } | 353 | } | ||
353 | pathcounter++; | 354 | pathcounter++; | ||
354 | } | 355 | } | ||
355 | #endif | 356 | #endif | ||
356 | /* this is a partial reimplementation of the above, it won't ensure a perfect 1:1 | 357 | /* this is a partial reimplementation of the above, it won't ensure a perfect 1:1 | ||
357 | porting, but will make many kde4 ksnsrc files work out of the box*/ | 358 | porting, but will make many kde4 ksnsrc files work out of the box*/ | ||
358 | //wallpaper is already managed in the case of !xdgTargetDirectory.isEmpty() | 359 | //wallpaper is already managed in the case of !xdgTargetDirectory.isEmpty() | ||
359 | if (!standardResourceDirectory.isEmpty() && standardResourceDirectory != QLatin1String("wallpaper")) { | 360 | if (!standardResourceDirectory.isEmpty() && standardResourceDirectory != QLatin1String("wallpaper")) { | ||
360 | QStandardPaths::StandardLocation location = QStandardPaths::TempLocation; | | |||
361 | //crude translation KStandardDirs names -> QStandardPaths enum | | |||
362 | if (standardResourceDirectory == QLatin1String("tmp")) { | | |||
363 | location = QStandardPaths::TempLocation; | | |||
364 | } else if (standardResourceDirectory == QLatin1String("config")) { | | |||
365 | location = QStandardPaths::ConfigLocation; | | |||
366 | } | | |||
367 | 361 | | |||
362 | if (standardResourceDirectory == QLatin1String("config")) { | ||||
368 | if (scope == ScopeUser) { | 363 | if (scope == ScopeUser) { | ||
369 | installdir = QStandardPaths::writableLocation(location); | 364 | installdir = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation); | ||
370 | } else { // system scope | 365 | } else { // system scope | ||
371 | installdir = QStandardPaths::standardLocations(location).constLast(); | 366 | installdir = QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).constLast(); | ||
367 | } | ||||
368 | } else { | ||||
369 | // no need for separate handling for system scope in case of tmp folder | ||||
370 | // TODO: ideally we would clean-up after ourselves, once the installation post processing is done | ||||
371 | // the responsilbility for that is yet to be defined, and would also include this temporary dir | ||||
372 | QTemporaryDir tempDir(QDir::tempPath() + QLatin1String("/kns-XXXXXX")); | ||||
373 | tempDir.setAutoRemove(false); | ||||
374 | installdir = tempDir.path(); | ||||
372 | } | 375 | } | ||
373 | pathcounter++; | 376 | pathcounter++; | ||
374 | } | 377 | } | ||
375 | if (!targetDirectory.isEmpty() && targetDirectory != QLatin1String("/")) { | 378 | if (!targetDirectory.isEmpty() && targetDirectory != QLatin1String("/")) { | ||
376 | if (scope == ScopeUser) { | 379 | if (scope == ScopeUser) { | ||
377 | installdir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + targetDirectory + QLatin1Char('/'); | 380 | installdir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + targetDirectory + QLatin1Char('/'); | ||
378 | } else { // system scope | 381 | } else { // system scope | ||
379 | installdir = QStandardPaths::locate(QStandardPaths::GenericDataLocation, targetDirectory, QStandardPaths::LocateDirectory) + QLatin1Char('/'); | 382 | installdir = QStandardPaths::locate(QStandardPaths::GenericDataLocation, targetDirectory, QStandardPaths::LocateDirectory) + QLatin1Char('/'); | ||
▲ Show 20 Lines • Show All 148 Lines • ▼ Show 20 Line(s) | 496 | if ((!isarchive && standardResourceDirectory == QLatin1String("wallpaper")) || | |||
528 | // FIXME: what must be done now is to update the cache *again* | 531 | // FIXME: what must be done now is to update the cache *again* | ||
529 | // in order to set the new payload filename (on root tag only) | 532 | // in order to set the new payload filename (on root tag only) | ||
530 | // - this might or might not need to take uncompression into account | 533 | // - this might or might not need to take uncompression into account | ||
531 | // FIXME: for updates, we might need to force an overwrite (that is, deleting before) | 534 | // FIXME: for updates, we might need to force an overwrite (that is, deleting before) | ||
532 | QFile file(payloadfile); | 535 | QFile file(payloadfile); | ||
533 | bool success = true; | 536 | bool success = true; | ||
534 | const bool update = ((entry.status() == KNS3::Entry::Updateable) || (entry.status() == KNS3::Entry::Updating)); | 537 | const bool update = ((entry.status() == KNS3::Entry::Updateable) || (entry.status() == KNS3::Entry::Updating)); | ||
535 | 538 | | |||
536 | if (QFile::exists(installpath) && QDir::tempPath() != installdir) { | 539 | if (QFile::exists(installpath)) { | ||
537 | if (!update) { | 540 | // always remove in case it's already present and in a temporary directory, as it's just intermediate storage | ||
541 | if (!update && !installdir.startsWith(QDir::tempPath())) { | ||||
538 | Question question(Question::ContinueCancelQuestion); | 542 | Question question(Question::ContinueCancelQuestion); | ||
539 | question.setQuestion(i18n("Overwrite existing file?") + QStringLiteral("\n'") + installpath + QLatin1Char('\'')); | 543 | question.setQuestion(i18n("Overwrite existing file?") + QStringLiteral("\n'") + installpath + QLatin1Char('\'')); | ||
540 | question.setTitle(i18n("Download File")); | 544 | question.setTitle(i18n("Download File")); | ||
541 | if(question.ask() != Question::ContinueResponse) { | 545 | if(question.ask() != Question::ContinueResponse) { | ||
542 | return QStringList(); | 546 | return QStringList(); | ||
543 | } | 547 | } | ||
544 | } | 548 | } | ||
545 | success = QFile::remove(installpath); | 549 | success = QFile::remove(installpath); | ||
546 | } | 550 | } | ||
547 | if (success) { | 551 | if (success) { | ||
548 | //remove in case it's already present and in a temporary directory, so we get to actually use the path again | | |||
549 | if (installpath.startsWith(QDir::tempPath())) { | | |||
550 | file.remove(installpath); | | |||
551 | } | | |||
552 | success = file.rename(installpath); | 552 | success = file.rename(installpath); | ||
553 | qCDebug(KNEWSTUFFCORE) << "move: " << file.fileName() << " to " << installpath; | 553 | qCDebug(KNEWSTUFFCORE) << "move: " << file.fileName() << " to " << installpath; | ||
554 | } | 554 | } | ||
555 | if (!success) { | 555 | if (!success) { | ||
556 | qCCritical(KNEWSTUFFCORE) << "Cannot move file '" << payloadfile << "' to destination '" << installpath << "'"; | 556 | qCCritical(KNEWSTUFFCORE) << "Cannot move file '" << payloadfile << "' to destination '" << installpath << "'"; | ||
557 | return QStringList(); | 557 | return QStringList(); | ||
558 | } | 558 | } | ||
559 | installedFiles << installpath; | 559 | installedFiles << installpath; | ||
▲ Show 20 Lines • Show All 112 Lines • Show Last 20 Lines |