Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 3a21006f authored by Ragnar Thomsen's avatar Ragnar Thomsen

Handle locked RAR archives

RAR archives can have a "locked" property essentially making them
readonly. Currently, Ark doesn't handle this properly and fails silently
if the user tries to modify the archive (e.g. adding files).

This diff adds a virtual method ReadOnlyArchiveInterface::isLocked()
with a default implementation returning false. The method is overridden
by the RAR plugin which checks if the archive is locked when listing.
ReadWriteArchiveInterface::isReadOnly() checks isLocked() when
determining the readonly status of the archive.

BUG: 368851
FIXED-IN: 19.04.0
Differential Revision: D20122
parent 45fc55b9
......@@ -67,6 +67,13 @@ void CliRarTest::testArchive_data()
<< QFileInfo(archivePath).fileName()
<< false << true << Archive::Unencrypted
<< QStringLiteral("A");
archivePath = QFINDTESTDATA("data/locked_archive.rar");
QTest::newRow("locked archive")
<< archivePath
<< QFileInfo(archivePath).fileName()
<< true << false << Archive::Unencrypted
<< QStringLiteral("locked_archive");
}
void CliRarTest::testArchive()
......
......@@ -255,8 +255,17 @@ bool ReadOnlyArchiveInterface::hasBatchExtractionProgress() const
return false;
}
bool ReadOnlyArchiveInterface::isLocked() const
{
return false;
}
bool ReadWriteArchiveInterface::isReadOnly() const
{
if (isLocked()) {
return true;
}
// We set corrupt archives to read-only to avoid add/delete actions, that
// are likely to fail anyway.
if (isCorrupt()) {
......
......@@ -168,6 +168,11 @@ public:
*/
virtual bool hasBatchExtractionProgress() const;
/**
* @return Whether the archive is locked (RAR feature).
*/
virtual bool isLocked() const;
Q_SIGNALS:
/**
......
......@@ -42,6 +42,7 @@ CliPlugin::CliPlugin(QObject *parent, const QVariantList& args)
, m_isPasswordProtected(false)
, m_isSolid(false)
, m_isRAR5(false)
, m_isLocked(false)
, m_remainingIgnoreLines(1) //The first line of UNRAR output is empty.
, m_linesComment(0)
{
......@@ -216,6 +217,9 @@ bool CliPlugin::handleUnrar5Line(const QString &line)
emit compressionMethodFound(QStringLiteral("RAR5"));
m_isRAR5 = true;
}
if (line.contains(QLatin1String("lock"))) {
m_isLocked = true;
}
}
return true;
}
......@@ -369,6 +373,8 @@ bool CliPlugin::handleUnrar4Line(const QString &line)
m_parseState = ParseStateEntryFileName;
} else if (line.startsWith(QLatin1String("Volume "))) {
m_numberOfVolumes++;
} else if (line == QLatin1String("Lock is present")) {
m_isLocked = true;
}
return true;
}
......@@ -601,4 +607,9 @@ bool CliPlugin::isFileExistsFileName(const QString &line)
line.contains(QLatin1String(" already exists. Overwrite it"))); // unrar 3 & 4
}
bool CliPlugin::isLocked() const
{
return m_isLocked;
}
#include "cliplugin.moc"
......@@ -45,6 +45,7 @@ public:
bool isDiskFullMsg(const QString &line) override;
bool isFileExistsMsg(const QString &line) override;
bool isFileExistsFileName(const QString &line) override;
bool isLocked() const override;
private:
......@@ -73,6 +74,7 @@ private:
bool m_isPasswordProtected;
bool m_isSolid;
bool m_isRAR5;
bool m_isLocked;
int m_remainingIgnoreLines;
int m_linesComment;
......
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