Commit 496b7686 authored by Elvis Angelaccio's avatar Elvis Angelaccio
Browse files

Don't list non-existing archives

This issue was supposed to be fixed by commit e5fcaedc,
but actually that patch only addressed the Archive::list() issued by the Part/ArchiveModel.

This patch generalizes the check for the "private" Archive::list() calls as well.

This slightly changes the expected values in the unit test for the properties of
a non-existing archive.

Differential Revision: D1133
parent 67e2c12c
......@@ -62,8 +62,8 @@ void ArchiveTest::testProperties_data()
QTest::newRow("non-existent tar archive")
<< archivePath
<< QStringLiteral("foo")
<< false << false << true << Archive::Unencrypted
<< QStringLiteral("foo");
<< false << false << false << Archive::Unencrypted
<< QString();
// Test dummy source code tarball.
archivePath = QFINDTESTDATA("data/code-x.y.z.tar.gz");
......
......@@ -339,6 +339,10 @@ KJob* Archive::create()
ListJob* Archive::list()
{
if (!QFileInfo::exists(fileName())) {
return Q_NULLPTR;
}
qCDebug(ARK) << "Going to list files";
ListJob *job = new ListJob(m_iface, this);
......@@ -426,6 +430,9 @@ void Archive::listIfNotListed()
{
if (!m_hasBeenListed) {
ListJob *job = list();
if (!job) {
return;
}
connect(job, &ListJob::userQuery, this, &Archive::onUserQuery);
......
......@@ -196,7 +196,12 @@ public:
KJob* open();
KJob* create();
/**
* @return A ListJob if the archive already exists. A null pointer otherwise.
*/
ListJob* list();
DeleteJob* deleteFiles(const QList<QVariant> & files);
/**
......
......@@ -875,7 +875,7 @@ Kerfuffle::Archive* ArchiveModel::archive() const
return m_archive.data();
}
KJob* ArchiveModel::setArchive(Kerfuffle::Archive *archive, bool existingArchive)
KJob* ArchiveModel::setArchive(Kerfuffle::Archive *archive)
{
m_archive.reset(archive);
......@@ -886,19 +886,18 @@ KJob* ArchiveModel::setArchive(Kerfuffle::Archive *archive, bool existingArchive
Kerfuffle::ListJob *job = Q_NULLPTR;
m_newArchiveEntries.clear();
if (m_archive && existingArchive) {
if (m_archive) {
job = m_archive->list(); // TODO: call "open" or "create"?
if (job) {
connect(job, &Kerfuffle::ListJob::newEntry, this, &ArchiveModel::slotNewEntryFromSetArchive);
connect(job, &Kerfuffle::ListJob::result, this, &ArchiveModel::slotLoadingFinished);
connect(job, &Kerfuffle::ListJob::userQuery, this, &ArchiveModel::slotUserQuery);
connect(job, &Kerfuffle::ListJob::newEntry, this, &ArchiveModel::slotNewEntryFromSetArchive);
emit loadingStarted();
connect(job, &Kerfuffle::ListJob::result, this, &ArchiveModel::slotLoadingFinished);
connect(job, &Kerfuffle::ListJob::userQuery, this, &ArchiveModel::slotUserQuery);
emit loadingStarted();
// TODO: make sure if it's ok to not have calls to beginRemoveColumns here
m_showColumns.clear();
// TODO: make sure if it's ok to not have calls to beginRemoveColumns here
m_showColumns.clear();
}
}
beginResetModel();
endResetModel();
......
......@@ -63,7 +63,7 @@ public:
QMimeData * mimeData(const QModelIndexList & indexes) const Q_DECL_OVERRIDE;
bool dropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent) Q_DECL_OVERRIDE;
KJob* setArchive(Kerfuffle::Archive *archive, bool existingArchive = false);
KJob* setArchive(Kerfuffle::Archive *archive);
Kerfuffle::Archive *archive() const;
Kerfuffle::ArchiveEntry entryForIndex(const QModelIndex &index);
......
......@@ -572,7 +572,7 @@ bool Part::openFile()
Q_ASSERT(archive->isValid());
// Plugin loaded successfully.
KJob *job = m_model->setArchive(archive.take(), localFileInfo.exists());
KJob *job = m_model->setArchive(archive.take());
if (job) {
registerJob(job);
job->start();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment