/** * This function recreate a zip in dest with all files from src * except meta.xml */ bool copyZipToZip( const KZip * src, KZip * dest) { KArchiveDirectory * src_dir; KArchiveFile * input_file; QPtrStack<KArchiveDirectory> src_dirStack ; QStringList dirEntries; QStringList curDirName; QStringList::Iterator it; KArchiveEntry* curEntry; QString filename = QString::null; src_dirStack.push ( src->directory() ); do { src_dir = src_dirStack.pop(); curDirName.append(src_dir->name()); dirEntries = src_dir->entries(); /* We now iterate over all entries and create entries in dest */ for ( it = dirEntries.begin(); it != dirEntries.end(); ++it ) { if ( *it == metafile ) continue; curEntry = src_dir->entry( *it ); if (curEntry->isFile()) { input_file = dynamic_cast<KArchiveFile*>( curEntry ); QByteArray b = input_file->data(); if (curDirName.isEmpty() || src_dir->name()=="/"){ filename = *it; } else { filename = curDirName.join("/") + "/" + *it; } dest->writeFile(filename , QString::null, QString::null, b.count(), b.data() ); } else if (curEntry->isDirectory()) { src_dirStack.push( dynamic_cast<KArchiveDirectory*>( curEntry ) ); } else { kdDebug(7034) << *it << " is a unknown type. Aborting." << endl; return false; } } curDirName.pop_back(); } while ( ! src_dirStack.isEmpty() ); return true; }
void KArchiveDirectory::copyTo(const QString &dest, bool recursiveCopy) const { QDir root; PosSortedPtrList fileList; QMap< int, QString > fileToDir; QStringList::Iterator it; // placeholders for iterated items KArchiveDirectory *curDir; QString curDirName; QStringList dirEntries; KArchiveEntry *curEntry; KArchiveFile *curFile; QPtrStack< KArchiveDirectory > dirStack; QValueStack< QString > dirNameStack; dirStack.push(this); // init stack at current directory dirNameStack.push(dest); // ... with given path do { curDir = dirStack.pop(); curDirName = dirNameStack.pop(); root.mkdir(curDirName); dirEntries = curDir->entries(); for(it = dirEntries.begin(); it != dirEntries.end(); ++it) { curEntry = curDir->entry(*it); if(!curEntry->symlink().isEmpty()) { const QString linkName = curDirName + '/' + curEntry->name(); kdDebug() << "symlink(" << curEntry->symlink() << ',' << linkName << ')'; if(!::symlink(curEntry->symlink().local8Bit(), linkName.local8Bit())) { kdDebug() << "symlink(" << curEntry->symlink() << ',' << linkName << ") failed:" << strerror(errno); } } else { if(curEntry->isFile()) { curFile = dynamic_cast< KArchiveFile * >(curEntry); if(curFile) { fileList.append(curFile); fileToDir.insert(curFile->position(), curDirName); } } if(curEntry->isDirectory()) if(recursiveCopy) { KArchiveDirectory *ad = dynamic_cast< KArchiveDirectory * >(curEntry); if(ad) { dirStack.push(ad); dirNameStack.push(curDirName + "/" + curEntry->name()); } } } } } while(!dirStack.isEmpty()); fileList.sort(); // sort on m_pos, so we have a linear access KArchiveFile *f; for(f = fileList.first(); f; f = fileList.next()) { int pos = f->position(); f->copyTo(fileToDir[pos]); } }