Commit bb76f994 authored by Elvis Angelaccio's avatar Elvis Angelaccio
Browse files

Fix archives with single files detected as single folder

If an archive contains only one file, there is no folder in it and
thus is wrong to claim that it is a single folder archive.

If the archive instead contains only one empty folder, we can and should say that it's
single folder.

The unit tests are updated to assert this.
parent 73fa5465
......@@ -189,6 +189,8 @@ ListJob::ListJob(ReadOnlyArchiveInterface *interface, QObject *parent)
, m_isSingleFolderArchive(true)
, m_isPasswordProtected(false)
, m_extractedFilesSize(0)
, m_dirCount(0)
, m_filesCount(0)
{
qCDebug(ARK) << "ListJob started";
connect(this, &ListJob::newEntry, this, &ListJob::onNewEntry);
......@@ -217,6 +219,10 @@ bool ListJob::isPasswordProtected() const
bool ListJob::isSingleFolderArchive() const
{
if (m_filesCount == 1 && m_dirCount == 0) {
return false;
}
return m_isSingleFolderArchive;
}
......@@ -225,6 +231,12 @@ void ListJob::onNewEntry(const ArchiveEntry& entry)
m_extractedFilesSize += entry[ Size ].toLongLong();
m_isPasswordProtected |= entry [ IsPasswordProtected ].toBool();
if (entry[IsDirectory].toBool()) {
m_dirCount++;
} else {
m_filesCount++;
}
if (m_isSingleFolderArchive) {
const QString fileName(entry[FileName].toString());
const QString basePath(fileName.split(QLatin1Char( '/' )).at(0));
......
......@@ -113,6 +113,8 @@ private:
QString m_subfolderName;
QString m_basePath;
qlonglong m_extractedFilesSize;
qlonglong m_dirCount;
qlonglong m_filesCount;
private slots:
void onNewEntry(const ArchiveEntry&);
......
......@@ -69,7 +69,7 @@ void ArchiveTest::testProperties_data()
QTest::newRow("encrypted zip, single entry")
<< archivePath
<< QFileInfo(archivePath).fileName()
<< false << true << true
<< false << false << true
// FIXME: possibly a bug? I was expecting to get "archivetest_encrypted" as subfolder name...
<< QStringLiteral("foo.txt");
......@@ -77,7 +77,7 @@ void ArchiveTest::testProperties_data()
QTest::newRow("simple zip, one unencrypted entry")
<< archivePath
<< QFileInfo(archivePath).fileName()
<< false << true << false
<< false << false << false
// FIXME: possibly a bug? I was expecting to get "archivetest_encrypted" as subfolder name...
<< QStringLiteral("foo.txt");
}
......
[
{
"FileName": "aDir/",
"IsDirectory": true
}
]
......@@ -166,11 +166,13 @@ void JobsTest::testListJob_data()
<< QStringList {QStringLiteral("aDirectory/"), QStringLiteral("bar.txt"), QStringLiteral("foo.txt")};
QTest::newRow("archive-singlefile.json") << QFINDTESTDATA("data/archive-singlefile.json")
<< 0LL << false
// FIXME: why do we consider archives with only one file as single folder?
<< true
<< 0LL << false << false
<< QStringList {QStringLiteral("a.txt")};
QTest::newRow("archive-emptysinglefolder.json") << QFINDTESTDATA("data/archive-emptysinglefolder.json")
<< 0LL << false << true
<< QStringList {QStringLiteral("aDir/")};
QTest::newRow("archive-unorderedsinglefolder.json") << QFINDTESTDATA("data/archive-unorderedsinglefolder.json")
<< 0LL << false << true
<< QStringList {
......
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