Changeset View
Changeset View
Standalone View
Standalone View
src/core/installation.cpp
Show First 20 Lines • Show All 412 Lines • ▼ Show 20 Line(s) | 397 | #endif | |||
---|---|---|---|---|---|
413 | QDir().mkpath(installdir); | 413 | QDir().mkpath(installdir); | ||
414 | } | 414 | } | ||
415 | 415 | | |||
416 | return installdir; | 416 | return installdir; | ||
417 | } | 417 | } | ||
418 | 418 | | |||
419 | QStringList Installation::installDownloadedFileAndUncompress(const KNSCore::EntryInternal &entry, const QString &payloadfile, const QString installdir) | 419 | QStringList Installation::installDownloadedFileAndUncompress(const KNSCore::EntryInternal &entry, const QString &payloadfile, const QString installdir) | ||
420 | { | 420 | { | ||
421 | QString installpath(payloadfile); | | |||
422 | // Collect all files that were installed | 421 | // Collect all files that were installed | ||
423 | QStringList installedFiles; | 422 | QStringList installedFiles; | ||
424 | 423 | | |||
425 | if (!isRemote()) { | 424 | if (!isRemote()) { | ||
426 | bool isarchive = true; | 425 | bool isarchive = true; | ||
427 | 426 | | |||
428 | // respect the uncompress flag in the knsrc | 427 | // respect the uncompress flag in the knsrc | ||
429 | if (uncompression == QLatin1String("always") || uncompression == QLatin1String("archive") || uncompression == QLatin1String("subdir")) { | 428 | if (uncompression == QLatin1String("always") || uncompression == QLatin1String("archive") || uncompression == QLatin1String("subdir")) { | ||
430 | // this is weird but a decompression is not a single name, so take the path instead | 429 | // this is weird but a decompression is not a single name, so take the path instead | ||
431 | installpath = installdir; | | |||
432 | QMimeDatabase db; | 430 | QMimeDatabase db; | ||
433 | QMimeType mimeType = db.mimeTypeForFile(payloadfile); | 431 | QMimeType mimeType = db.mimeTypeForFile(payloadfile); | ||
434 | qCDebug(KNEWSTUFFCORE) << "Postinstallation: uncompress the file"; | 432 | qCDebug(KNEWSTUFFCORE) << "Postinstallation: uncompress the file"; | ||
435 | 433 | | |||
436 | // FIXME: check for overwriting, malicious archive entries (../foo) etc. | 434 | // FIXME: check for overwriting, malicious archive entries (../foo) etc. | ||
437 | // FIXME: KArchive should provide "safe mode" for this! | 435 | // FIXME: KArchive should provide "safe mode" for this! | ||
438 | QScopedPointer<KArchive> archive; | 436 | QScopedPointer<KArchive> archive; | ||
439 | 437 | | |||
Show All 25 Lines | 458 | if (!success) { | |||
465 | // otherwise, just copy the file | 463 | // otherwise, just copy the file | ||
466 | isarchive = false; | 464 | isarchive = false; | ||
467 | } | 465 | } | ||
468 | 466 | | |||
469 | if (isarchive) { | 467 | if (isarchive) { | ||
470 | const KArchiveDirectory *dir = archive->directory(); | 468 | const KArchiveDirectory *dir = archive->directory(); | ||
471 | //if there is more than an item in the file, and we are requested to do so | 469 | //if there is more than an item in the file, and we are requested to do so | ||
472 | //put contents in a subdirectory with the same name as the file | 470 | //put contents in a subdirectory with the same name as the file | ||
471 | QString installpath; | ||||
473 | if (uncompression == QLatin1String("subdir") && dir->entries().count() > 1) { | 472 | if (uncompression == QLatin1String("subdir") && dir->entries().count() > 1) { | ||
474 | installpath = installdir + QLatin1Char('/') + QFileInfo(archive->fileName()).baseName(); | 473 | installpath = installdir + QLatin1Char('/') + QFileInfo(archive->fileName()).baseName(); | ||
474 | } else { | ||||
475 | installpath = installdir; | ||||
475 | } | 476 | } | ||
476 | dir->copyTo(installpath); | | |||
477 | 477 | | |||
478 | if (dir->copyTo(installpath)) { | ||||
478 | installedFiles << archiveEntries(installpath, dir); | 479 | installedFiles << archiveEntries(installpath, dir); | ||
479 | installedFiles << installpath + QLatin1Char('/'); | 480 | installedFiles << installpath + QLatin1Char('/'); | ||
481 | } else | ||||
482 | qCWarning(KNEWSTUFFCORE) << "could not install" << entry.name() << "to" << installpath; | ||||
480 | 483 | | |||
481 | archive->close(); | 484 | archive->close(); | ||
482 | QFile::remove(payloadfile); | 485 | QFile::remove(payloadfile); | ||
483 | } | 486 | } | ||
484 | } | 487 | } | ||
485 | } | 488 | } | ||
486 | 489 | | |||
487 | qCDebug(KNEWSTUFFCORE) << "isarchive: " << isarchive; | 490 | qCDebug(KNEWSTUFFCORE) << "isarchive: " << isarchive; | ||
Show All 25 Lines | 513 | if (source.url().startsWith(QLatin1String("http://newstuff.kde.org/cgi-bin/hotstuff-access?file="))) { | |||
513 | if (lastSlash >= 0) { | 516 | if (lastSlash >= 0) { | ||
514 | installfile = installfile.mid(lastSlash); | 517 | installfile = installfile.mid(lastSlash); | ||
515 | } | 518 | } | ||
516 | } | 519 | } | ||
517 | if (installfile.isEmpty()) { | 520 | if (installfile.isEmpty()) { | ||
518 | installfile = source.fileName(); | 521 | installfile = source.fileName(); | ||
519 | } | 522 | } | ||
520 | } | 523 | } | ||
521 | installpath = installdir + QLatin1Char('/') + installfile; | 524 | QString installpath = installdir + QLatin1Char('/') + installfile; | ||
522 | 525 | | |||
523 | qCDebug(KNEWSTUFFCORE) << "Install to file " << installpath; | 526 | qCDebug(KNEWSTUFFCORE) << "Install to file " << installpath; | ||
524 | // FIXME: copy goes here (including overwrite checking) | 527 | // FIXME: copy goes here (including overwrite checking) | ||
525 | // FIXME: what must be done now is to update the cache *again* | 528 | // FIXME: what must be done now is to update the cache *again* | ||
526 | // in order to set the new payload filename (on root tag only) | 529 | // in order to set the new payload filename (on root tag only) | ||
527 | // - this might or might not need to take uncompression into account | 530 | // - this might or might not need to take uncompression into account | ||
528 | // FIXME: for updates, we might need to force an overwrite (that is, deleting before) | 531 | // FIXME: for updates, we might need to force an overwrite (that is, deleting before) | ||
529 | QFile file(payloadfile); | 532 | QFile file(payloadfile); | ||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Line(s) | 589 | { | |||
608 | foreach (const QString &file, entry.installedFiles()) { | 611 | foreach (const QString &file, entry.installedFiles()) { | ||
609 | if (file.endsWith('/')) { | 612 | if (file.endsWith('/')) { | ||
610 | QDir dir; | 613 | QDir dir; | ||
611 | bool worked = dir.rmdir(file); | 614 | bool worked = dir.rmdir(file); | ||
612 | if (!worked) { | 615 | if (!worked) { | ||
613 | // Maybe directory contains user created files, ignore it | 616 | // Maybe directory contains user created files, ignore it | ||
614 | continue; | 617 | continue; | ||
615 | } | 618 | } | ||
619 | } else if (file.endsWith(QLatin1String("/*"))) { | ||||
620 | QDir dir(file.left(file.size()-2)); | ||||
621 | bool worked = dir.removeRecursively(); | ||||
622 | if (!worked) { | ||||
623 | qCWarning(KNEWSTUFFCORE) << "Couldn't remove" << dir.path(); | ||||
624 | continue; | ||||
625 | } | ||||
616 | } else { | 626 | } else { | ||
617 | QFileInfo info(file); | 627 | QFileInfo info(file); | ||
618 | if (info.exists() || info.isSymLink()) { | 628 | if (info.exists() || info.isSymLink()) { | ||
619 | bool worked = QFile::remove(file); | 629 | bool worked = QFile::remove(file); | ||
620 | if (!worked) { | 630 | if (!worked) { | ||
621 | qWarning() << "unable to delete file " << file; | 631 | qWarning() << "unable to delete file " << file; | ||
622 | return; | 632 | return; | ||
623 | } | 633 | } | ||
Show All 13 Lines | 646 | { | |||
637 | Q_UNUSED(result) | 647 | Q_UNUSED(result) | ||
638 | // Deprecated, was wired up to defunct Security class. | 648 | // Deprecated, was wired up to defunct Security class. | ||
639 | } | 649 | } | ||
640 | 650 | | |||
641 | QStringList Installation::archiveEntries(const QString &path, const KArchiveDirectory *dir) | 651 | QStringList Installation::archiveEntries(const QString &path, const KArchiveDirectory *dir) | ||
642 | { | 652 | { | ||
643 | QStringList files; | 653 | QStringList files; | ||
644 | foreach (const QString &entry, dir->entries()) { | 654 | foreach (const QString &entry, dir->entries()) { | ||
645 | QString childPath = path + QLatin1Char('/') + entry; | 655 | const auto currentEntry = dir->entry(entry); | ||
646 | if (dir->entry(entry)->isFile()) { | | |||
647 | files << childPath; | | |||
648 | } | | |||
649 | 656 | | |||
650 | if (dir->entry(entry)->isDirectory()) { | 657 | const QString childPath = path + QLatin1Char('/') + entry; | ||
651 | const KArchiveDirectory *childDir = static_cast<const KArchiveDirectory *>(dir->entry(entry)); | 658 | if (currentEntry->isFile()) { | ||
652 | files << archiveEntries(childPath, childDir); | 659 | files << childPath; | ||
653 | files << childPath + QLatin1Char('/'); | 660 | } else if (currentEntry->isDirectory()) { | ||
661 | files << childPath + QStringLiteral("/*"); | ||||
654 | } | 662 | } | ||
655 | } | 663 | } | ||
656 | return files; | 664 | return files; | ||
657 | } | 665 | } | ||
658 | 666 | |