Commit d2879933 authored by Toni Asensi Esteve's avatar Toni Asensi Esteve
Browse files

Last steps to normalize some compressed file types and to deduplicate code in...

Last steps to normalize some compressed file types and to deduplicate code in krarc.cpp and krarchandler.cpp.

This is the last part of the operation aimed to:
    - Normalize the file types of several compressed file types
    - Remove duplicate code in krarc.cpp and krarchandler.cpp.

After the present changes: there isn't any compressed file type with a '/' as a first character. For more information it can be seen:
    - https://phabricator.kde.org/D1707
    - https://phabricator.kde.org/T2768

Differential Revision: https://phabricator.kde.org/D2508
Fixes T2768
parent b18b0a51
......@@ -1637,16 +1637,7 @@ bool kio_krarcProtocol::checkStatus(int exitCode)
{
KRFUNC;
KRDEBUG(exitCode);
// if this code is changed, the code of KRarcHandler::checkStatus() must be reviewed
if (arcType == "zip" || arcType == "rar" || arcType == "7z")
return exitCode == 0 || exitCode == 1;
else if (arcType == "ace" || arcType == "bzip2" || arcType == "lha" || arcType == "rpm" || arcType == "arj")
return exitCode == 0;
else if (arcType == "gzip" || arcType == "lzma" || arcType == "xz")
return exitCode == 0 || exitCode == 2;
else
return exitCode == 0;
return KrArcBaseManager::checkStatus(arcType, exitCode);
}
void kio_krarcProtocol::checkIf7zIsEncrypted(bool &encrypted, QString fileName)
......
......@@ -79,7 +79,7 @@ protected:
private:
void get(const QUrl &url, int tries);
/** checks if the exit code is OK. */
/** checks if a returned status ("exit code") of an archiving-related process is OK. */
bool checkStatus(int exitCode);
/** service function for parseLine. */
QString nextWord(QString &s, char d = ' ');
......
......@@ -34,6 +34,26 @@ KrArcBaseManager::AutoDetectParams KrArcBaseManager::autoDetectParams[] = {{"zip
int KrArcBaseManager::autoDetectElems = sizeof(autoDetectParams) / sizeof(AutoDetectParams);
const int KrArcBaseManager::maxLenType = 5;
//! Checks if a returned status ("exit code") of an archiving-related process is OK
/*!
\param arcType A short QString which contains an identifier of the type of the archive.
\param exitCode The returned status ("exit code") of an archiving-related process.
\return If the exit code means that the archiving-related process ended without errors.
*/
bool KrArcBaseManager::checkStatus(const QString &arcType, int exitCode)
{
if (arcType == "zip" || arcType == "rar" || arcType == "7z")
return exitCode == 0 || exitCode == 1;
else if (arcType == "ace" || arcType == "bzip2" || arcType == "lha" || arcType == "rpm" || arcType == "cpio" ||
arcType == "tar" || arcType == "tarz" || arcType == "tbz" || arcType == "tgz" || arcType == "arj" ||
arcType == "deb" || arcType == "tlz" || arcType == "txz")
return exitCode == 0;
else if (arcType == "gzip" || arcType == "lzma" || arcType == "xz")
return exitCode == 0 || exitCode == 2;
else
return exitCode == 0;
}
QString KrArcBaseManager::detectArchive(bool &encrypted, QString fileName, bool checkEncrypted, bool fast)
{
encrypted = false;
......
......@@ -41,6 +41,8 @@ protected:
//! The maximum length of a short QString that represents the type of a file
static const int maxLenType;
static bool checkStatus(const QString &, int);
public:
KrArcBaseManager() {}
QString detectArchive(bool &, QString, bool = true, bool = false);
......
......@@ -140,7 +140,7 @@ bool KRarcHandler::arcSupported(QString type)
type = getShortTypeFromMime(type);
}
if ((type == "zip" || type == "/zip") && lst.contains("unzip"))
if (type == "zip" && lst.contains("unzip"))
return true;
else if (type == "tar" && lst.contains("tar"))
return true;
......@@ -686,17 +686,7 @@ QString KRarcHandler::getType(bool &encrypted, QString fileName, QString mime, b
bool KRarcHandler::checkStatus(QString type, int exitCode)
{
// if this code is changed, the code of kio_krarcProtocol::checkStatus() must be reviewed
if (type == "zip" || type == "rar" || type == "7z")
return exitCode == 0 || exitCode == 1;
else if (type == "ace" || type == "bzip2" || type == "lha" || type == "rpm" || type == "cpio" ||
type == "tar" || type == "tarz" || type == "tbz" || type == "tgz" || type == "arj" ||
type == "deb" || type == "tlz" || type == "txz")
return exitCode == 0;
else if (type == "gzip" || type == "lzma" || type == "xz")
return exitCode == 0 || exitCode == 2;
else
return exitCode == 0;
return KrArcBaseManager::checkStatus(type, exitCode);
}
void KRarcHandler::checkIf7zIsEncrypted(bool &encrypted, QString fileName)
......
......@@ -85,7 +85,7 @@ public:
// detects the archive type
void checkIf7zIsEncrypted(bool &, QString);
private:
// checks if the returned status is correct
//! checks if a returned status ("exit code") of an archiving-related process is OK
static bool checkStatus(QString type, int exitCode);
static bool openWallet();
......
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