From c772aa4756b63859aef934d27eed4e40c65d3ad2 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Thu, 6 Oct 2022 21:33:53 +0300 Subject: [PATCH] ark: emit entries for added files from libarchive plugin Signed-off-by: Ivailo Monev --- ark/kerfuffle/archiveinterface.h | 5 +- ark/plugins/libarchive/libarchivehandler.cpp | 79 ++++++++++++-------- 2 files changed, 50 insertions(+), 34 deletions(-) diff --git a/ark/kerfuffle/archiveinterface.h b/ark/kerfuffle/archiveinterface.h index 3db7dad1..e3e2fd86 100644 --- a/ark/kerfuffle/archiveinterface.h +++ b/ark/kerfuffle/archiveinterface.h @@ -104,6 +104,9 @@ signals: void finished(bool result); void userQuery(Query *query); +public: + static QString permissionsString(mode_t perm); + protected: QString password() const; /** @@ -114,8 +117,6 @@ protected: */ void setWaitForFinishedSignal(bool value); - static QString permissionsString(mode_t perm); - private: QString m_filename; QString m_password; diff --git a/ark/plugins/libarchive/libarchivehandler.cpp b/ark/plugins/libarchive/libarchivehandler.cpp index 47ef8319..67a165db 100644 --- a/ark/plugins/libarchive/libarchivehandler.cpp +++ b/ark/plugins/libarchive/libarchivehandler.cpp @@ -35,6 +35,22 @@ #include +static void copyEntry(ArchiveEntry *archiveentry, const KArchiveEntry *karchiveentry) +{ + archiveentry->insert(FileName, karchiveentry->pathname); + archiveentry->insert(InternalID, karchiveentry->pathname); + archiveentry->insert(Size, qlonglong(karchiveentry->size)); + archiveentry->insert(IsDirectory, S_ISDIR(karchiveentry->mode)); + archiveentry->insert(Permissions, ReadWriteArchiveInterface::permissionsString(karchiveentry->mode)); + archiveentry->insert(Owner, karchiveentry->username); + archiveentry->insert(Group, karchiveentry->groupname); + archiveentry->insert(Timestamp, QDateTime::fromTime_t(karchiveentry->mtime)); + archiveentry->insert(IsPasswordProtected, karchiveentry->encrypted); + if (!karchiveentry->symlink.isEmpty()) { + archiveentry->insert(Link, karchiveentry->symlink); + } +} + LibArchiveInterface::LibArchiveInterface(QObject *parent, const QVariantList &args) : ReadWriteArchiveInterface(parent, args) { @@ -54,22 +70,11 @@ bool LibArchiveInterface::list() foreach (const KArchiveEntry &karchiveentry, karchive.list()) { ArchiveEntry archiveentry; - archiveentry[FileName] = karchiveentry.pathname; - archiveentry[InternalID] = karchiveentry.pathname; - archiveentry[Size] = qlonglong(karchiveentry.size); - archiveentry[IsDirectory] = S_ISDIR(karchiveentry.mode); - archiveentry[Permissions] = ReadWriteArchiveInterface::permissionsString(karchiveentry.mode); - archiveentry[Owner] = karchiveentry.username; - archiveentry[Group] = karchiveentry.groupname; - archiveentry[Timestamp] = QDateTime::fromTime_t(karchiveentry.mtime); - archiveentry[IsPasswordProtected] = karchiveentry.encrypted; - if (!karchiveentry.symlink.isEmpty()) { - archiveentry[Link] = karchiveentry.symlink; - } + copyEntry(&archiveentry, &karchiveentry); emit entry(archiveentry); } - emit progress(1.0); + emit progress(1.0); return true; } @@ -94,13 +99,13 @@ bool LibArchiveInterface::copyFiles(const QVariantList& files, const QString &de fileslist.append(variant.toString()); } } - if (karchive.extract(fileslist, destinationDirectory, preservePaths)) { - emit progress(1.0); - return true; + if (!karchive.extract(fileslist, destinationDirectory, preservePaths)) { + emit error(karchive.errorString()); + return false; } - emit error(karchive.errorString()); - return false; + emit progress(1.0); + return true; } bool LibArchiveInterface::addFiles(const QStringList &files, const CompressionOptions &options) @@ -122,14 +127,23 @@ bool LibArchiveInterface::addFiles(const QStringList &files, const CompressionOp return false; } - const QString strip = (QDir::cleanPath(globalWorkDir) + QDir::separator()); - if (karchive.add(files, QFile::encodeName(strip), QFile::encodeName(rootNode))) { - emit progress(1.0); - return true; + const QList oldEntries = karchive.list(); + const QString strip(QDir::cleanPath(globalWorkDir) + QDir::separator()); + if (!karchive.add(files, QFile::encodeName(strip), QFile::encodeName(rootNode))) { + emit error(karchive.errorString()); + return false; } - emit error(karchive.errorString()); - return false; + foreach (const KArchiveEntry &karchiveentry, karchive.list()) { + if (!oldEntries.contains(karchiveentry)) { + ArchiveEntry archiveentry; + copyEntry(&archiveentry, &karchiveentry); + emit entry(archiveentry); + } + } + + emit progress(1.0); + return true; } bool LibArchiveInterface::deleteFiles(const QVariantList &files) @@ -144,16 +158,17 @@ bool LibArchiveInterface::deleteFiles(const QVariantList &files) foreach (const QVariant &variant, files) { fileslist.append(variant.toString()); } - if (karchive.remove(fileslist)) { - foreach (const QString &file, fileslist) { - emit entryRemoved(file); - } - emit progress(1.0); - return true; + if (!karchive.remove(fileslist)) { + emit error(karchive.errorString()); + return false; } - emit error(karchive.errorString()); - return false; + foreach (const QString &file, fileslist) { + emit entryRemoved(file); + } + + emit progress(1.0); + return true; } KERFUFFLE_EXPORT_PLUGIN(LibArchiveInterface)