MCPcopy Create free account
hub / github.com/KDE/kdevelop / unpackArchive

Method unpackArchive

plugins/appwizard/appwizardplugin.cpp:429–474  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

427}
428
429bool AppWizardPlugin::unpackArchive(const KArchiveDirectory* dir, const QString& dest, const QStringList& skipList)
430{
431 qCDebug(PLUGIN_APPWIZARD) << "unpacking dir:" << dir->name() << "to" << dest;
432 const QStringList entries = dir->entries();
433 qCDebug(PLUGIN_APPWIZARD) << "entries:" << entries.join(QLatin1Char(','));
434
435 //This extra tempdir is needed just for the files that have special names,
436 //which may contain macros also files contain content with macros. So the
437 //easiest way to extract the files from the archive and then rename them
438 //and replace the macros is to use a tempdir and copy the file (and
439 //replacing while copying). This also allows one to easily remove all files,
440 //by just unlinking the tempdir
441 QTemporaryDir tdir;
442
443 bool ret = true;
444
445 for (const auto& entryName : entries) {
446 if (skipList.contains(entryName)) {
447 continue;
448 }
449
450 const auto entry = dir->entry(entryName);
451 if (entry->isDirectory()) {
452 const auto* subdir = static_cast<const KArchiveDirectory*>(entry);
453 const QString newdest = dest + QLatin1Char('/') + KMacroExpander::expandMacros(subdir->name(), m_variables);
454 if( !QFileInfo::exists( newdest ) )
455 {
456 QDir::root().mkdir( newdest );
457 }
458 ret |= unpackArchive(subdir, newdest);
459 }
460 else if (entry->isFile()) {
461 const auto* file = static_cast<const KArchiveFile*>(entry);
462 file->copyTo(tdir.path());
463 const QString destName = dest + QLatin1Char('/') + file->name();
464 if (!copyFileAndExpandMacros(QDir::cleanPath(tdir.path() + QLatin1Char('/') + file->name()),
465 KMacroExpander::expandMacros(destName, m_variables)))
466 {
467 KMessageBox::error(nullptr, i18n("The file %1 cannot be created.", dest));
468 return false;
469 }
470 }
471 }
472 tdir.remove();
473 return ret;
474}
475
476bool AppWizardPlugin::copyFileAndExpandMacros(const QString &source, const QString &dest)
477{

Callers

nothing calls this directly

Calls 11

rootFunction · 0.85
cleanPathFunction · 0.85
joinMethod · 0.80
entryMethod · 0.80
isDirectoryMethod · 0.80
mkdirMethod · 0.80
nameMethod · 0.45
containsMethod · 0.45
copyToMethod · 0.45
pathMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected