Changeset View
Changeset View
Standalone View
Standalone View
plugins/libzipplugin/libzipplugin.cpp
Show First 20 Lines • Show All 90 Lines • ▼ Show 20 Line(s) | 89 | if (!archive) { | |||
---|---|---|---|---|---|
91 | emit error(xi18n("Failed to open archive: %1", QString::fromUtf8(zip_error_strerror(&err)))); | 91 | emit error(xi18n("Failed to open archive: %1", QString::fromUtf8(zip_error_strerror(&err)))); | ||
92 | return false; | 92 | return false; | ||
93 | } | 93 | } | ||
94 | 94 | | |||
95 | // Fetch archive comment. | 95 | // Fetch archive comment. | ||
96 | m_comment = QString::fromUtf8(zip_get_archive_comment(archive, nullptr, ZIP_FL_ENC_GUESS)); | 96 | m_comment = QString::fromUtf8(zip_get_archive_comment(archive, nullptr, ZIP_FL_ENC_GUESS)); | ||
97 | 97 | | |||
98 | // Get number of archive entries. | 98 | // Get number of archive entries. | ||
99 | int nofEntries = zip_get_num_entries(archive, 0); | 99 | const auto nofEntries = zip_get_num_entries(archive, 0); | ||
100 | qCDebug(ARK) << "Found entries:" << nofEntries; | 100 | qCDebug(ARK) << "Found entries:" << nofEntries; | ||
101 | 101 | | |||
102 | // Loop through all archive entries. | 102 | // Loop through all archive entries. | ||
103 | for (int i = 0; i < nofEntries; i++) { | 103 | for (int i = 0; i < nofEntries; i++) { | ||
104 | 104 | | |||
105 | if (QThread::currentThread()->isInterruptionRequested()) { | 105 | if (QThread::currentThread()->isInterruptionRequested()) { | ||
106 | break; | 106 | break; | ||
107 | } | 107 | } | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | 147 | if (QFileInfo(e->fullPath()).isDir()) { | |||
151 | } | 151 | } | ||
152 | 152 | | |||
153 | QDirIterator it(e->fullPath(), | 153 | QDirIterator it(e->fullPath(), | ||
154 | QDir::AllEntries | QDir::Readable | | 154 | QDir::AllEntries | QDir::Readable | | ||
155 | QDir::Hidden | QDir::NoDotAndDotDot, | 155 | QDir::Hidden | QDir::NoDotAndDotDot, | ||
156 | QDirIterator::Subdirectories); | 156 | QDirIterator::Subdirectories); | ||
157 | 157 | | |||
158 | while (!QThread::currentThread()->isInterruptionRequested() && it.hasNext()) { | 158 | while (!QThread::currentThread()->isInterruptionRequested() && it.hasNext()) { | ||
159 | QString path = it.next(); | 159 | const QString path = it.next(); | ||
160 | 160 | | |||
161 | if (QFileInfo(path).isDir()) { | 161 | if (QFileInfo(path).isDir()) { | ||
162 | if (!writeEntry(archive, path, destination, options, true)) { | 162 | if (!writeEntry(archive, path, destination, options, true)) { | ||
163 | return false; | 163 | return false; | ||
164 | } | 164 | } | ||
165 | } else { | 165 | } else { | ||
166 | if (!writeEntry(archive, path, destination, options)) { | 166 | if (!writeEntry(archive, path, destination, options)) { | ||
167 | return false; | 167 | return false; | ||
▲ Show 20 Lines • Show All 185 Lines • ▼ Show 20 Line(s) | 341 | { | |||
353 | 353 | | |||
354 | qulonglong i = 0; | 354 | qulonglong i = 0; | ||
355 | foreach (const Archive::Entry* e, files) { | 355 | foreach (const Archive::Entry* e, files) { | ||
356 | 356 | | |||
357 | if (QThread::currentThread()->isInterruptionRequested()) { | 357 | if (QThread::currentThread()->isInterruptionRequested()) { | ||
358 | break; | 358 | break; | ||
359 | } | 359 | } | ||
360 | 360 | | |||
361 | qlonglong index = zip_name_locate(archive, e->fullPath().toUtf8(), ZIP_FL_ENC_GUESS); | 361 | const qlonglong index = zip_name_locate(archive, e->fullPath().toUtf8(), ZIP_FL_ENC_GUESS); | ||
362 | if (index == -1) { | 362 | if (index == -1) { | ||
363 | qCCritical(ARK) << "Could not find entry to delete:" << e->fullPath(); | 363 | qCCritical(ARK) << "Could not find entry to delete:" << e->fullPath(); | ||
364 | emit error(xi18n("Failed to delete entry: %1", e->fullPath())); | 364 | emit error(xi18n("Failed to delete entry: %1", e->fullPath())); | ||
365 | return false; | 365 | return false; | ||
366 | } | 366 | } | ||
367 | if (zip_delete(archive, index) == -1) { | 367 | if (zip_delete(archive, index) == -1) { | ||
368 | qCCritical(ARK) << "Could not delete entry" << e->fullPath() << ":" << zip_strerror(archive); | 368 | qCCritical(ARK) << "Could not delete entry" << e->fullPath() << ":" << zip_strerror(archive); | ||
369 | emit error(xi18n("Failed to delete entry: %1", QString::fromUtf8(zip_strerror(archive)))); | 369 | emit error(xi18n("Failed to delete entry: %1", QString::fromUtf8(zip_strerror(archive)))); | ||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Line(s) | 467 | { | |||
484 | 484 | | |||
485 | // Set password if known. | 485 | // Set password if known. | ||
486 | if (!password().isEmpty()) { | 486 | if (!password().isEmpty()) { | ||
487 | qCDebug(ARK) << "Password already known. Setting..."; | 487 | qCDebug(ARK) << "Password already known. Setting..."; | ||
488 | zip_set_default_password(archive, password().toUtf8()); | 488 | zip_set_default_password(archive, password().toUtf8()); | ||
489 | } | 489 | } | ||
490 | 490 | | |||
491 | // Get number of archive entries. | 491 | // Get number of archive entries. | ||
492 | qlonglong nofEntries; | 492 | const qlonglong nofEntries = extractAll ? zip_get_num_entries(archive, 0) : files.size(); | ||
493 | extractAll ? nofEntries = zip_get_num_entries(archive, 0) : nofEntries = files.size(); | | |||
494 | 493 | | |||
495 | // Extract entries. | 494 | // Extract entries. | ||
496 | m_overwriteAll = false; // Whether to overwrite all files | 495 | m_overwriteAll = false; // Whether to overwrite all files | ||
497 | m_skipAll = false; // Whether to skip all files | 496 | m_skipAll = false; // Whether to skip all files | ||
498 | if (extractAll) { | 497 | if (extractAll) { | ||
499 | // We extract all entries. | 498 | // We extract all entries. | ||
500 | for (qlonglong i = 0; i < nofEntries; i++) { | 499 | for (qlonglong i = 0; i < nofEntries; i++) { | ||
501 | if (QThread::currentThread()->isInterruptionRequested()) { | 500 | if (QThread::currentThread()->isInterruptionRequested()) { | ||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | 539 | { | |||
569 | if (isDirectory) { | 568 | if (isDirectory) { | ||
570 | QDir pDir = QFileInfo(destination).dir(); | 569 | QDir pDir = QFileInfo(destination).dir(); | ||
571 | pDir.cdUp(); | 570 | pDir.cdUp(); | ||
572 | parentDir = pDir.path(); | 571 | parentDir = pDir.path(); | ||
573 | } else { | 572 | } else { | ||
574 | parentDir = QFileInfo(destination).path(); | 573 | parentDir = QFileInfo(destination).path(); | ||
575 | } | 574 | } | ||
576 | // For top-level items, dont restore parent dir mtime. | 575 | // For top-level items, dont restore parent dir mtime. | ||
577 | bool restoreParentMtime = (parentDir + QDir::separator() != destDirCorrected); | 576 | const bool restoreParentMtime = (parentDir + QDir::separator() != destDirCorrected); | ||
578 | 577 | | |||
579 | time_t parent_mtime; | 578 | time_t parent_mtime; | ||
580 | if (restoreParentMtime) { | 579 | if (restoreParentMtime) { | ||
581 | parent_mtime = QFileInfo(parentDir).lastModified().toMSecsSinceEpoch() / 1000; | 580 | parent_mtime = QFileInfo(parentDir).lastModified().toMSecsSinceEpoch() / 1000; | ||
582 | } | 581 | } | ||
583 | 582 | | |||
584 | // Create parent directories for files. For directories create them. | 583 | // Create parent directories for files. For directories create them. | ||
585 | if (!QDir().mkpath(QFileInfo(destination).path())) { | 584 | if (!QDir().mkpath(QFileInfo(destination).path())) { | ||
▲ Show 20 Lines • Show All 266 Lines • Show Last 20 Lines |