Commit 19301ccc authored by Ilya Pominov's avatar Ilya Pominov Committed by Elvis Angelaccio
Browse files

libarchive: Represent file permissions as human readable string

parent 7809ba4a
Pipeline #252229 passed with stage
in 1 minute and 57 seconds
......@@ -13,6 +13,7 @@
#include <QDir>
#include <QFileInfo>
#include <qplatformdefs.h>
namespace Kerfuffle
{
......@@ -153,6 +154,52 @@ qulonglong ReadOnlyArchiveInterface::unpackedSize() const
return m_unpackedSize;
}
QString ReadOnlyArchiveInterface::permissionsToString(mode_t perm)
{
QString modeval;
if ((perm & S_IFMT) == S_IFDIR) {
modeval.append(QLatin1Char('d'));
} else if ((perm & S_IFMT) == S_IFLNK) {
modeval.append(QLatin1Char('l'));
} else {
modeval.append(QLatin1Char('-'));
}
modeval.append((perm & S_IRUSR) ? QLatin1Char('r') : QLatin1Char('-'));
modeval.append((perm & S_IWUSR) ? QLatin1Char('w') : QLatin1Char('-'));
if ((perm & S_ISUID) && (perm & S_IXUSR)) {
modeval.append(QLatin1Char('s'));
} else if ((perm & S_ISUID)) {
modeval.append(QLatin1Char('S'));
} else if ((perm & S_IXUSR)) {
modeval.append(QLatin1Char('x'));
} else {
modeval.append(QLatin1Char('-'));
}
modeval.append((perm & S_IRGRP) ? QLatin1Char('r') : QLatin1Char('-'));
modeval.append((perm & S_IWGRP) ? QLatin1Char('w') : QLatin1Char('-'));
if ((perm & S_ISGID) && (perm & S_IXGRP)) {
modeval.append(QLatin1Char('s'));
} else if ((perm & S_ISGID)) {
modeval.append(QLatin1Char('S'));
} else if ((perm & S_IXGRP)) {
modeval.append(QLatin1Char('x'));
} else {
modeval.append(QLatin1Char('-'));
}
modeval.append((perm & S_IROTH) ? QLatin1Char('r') : QLatin1Char('-'));
modeval.append((perm & S_IWOTH) ? QLatin1Char('w') : QLatin1Char('-'));
if ((perm & S_ISVTX) && (perm & S_IXOTH)) {
modeval.append(QLatin1Char('t'));
} else if ((perm & S_ISVTX)) {
modeval.append(QLatin1Char('T'));
} else if ((perm & S_IXOTH)) {
modeval.append(QLatin1Char('x'));
} else {
modeval.append(QLatin1Char('-'));
}
return modeval;
}
QStringList ReadOnlyArchiveInterface::entryFullPaths(const QVector<Archive::Entry*> &entries, PathFormat format)
{
QStringList filesList;
......
......@@ -167,6 +167,8 @@ public:
*/
qulonglong unpackedSize() const;
static QString permissionsToString(mode_t perm);
Q_SIGNALS:
/**
......
......@@ -474,7 +474,7 @@ void LibarchivePlugin::emitEntryFromArchiveEntry(struct archive_entry *aentry)
const mode_t mode = archive_entry_mode(aentry);
if (mode != 0) {
e->setProperty("permissions", QString::number(mode, 8));
e->setProperty("permissions", permissionsToString(mode));
}
e->setProperty("isExecutable", mode & (S_IXUSR | S_IXGRP | S_IXOTH));
......
......@@ -965,52 +965,6 @@ bool LibzipPlugin::copyFiles(const QVector<Archive::Entry*> &files, Archive::Ent
return true;
}
QString LibzipPlugin::permissionsToString(mode_t perm)
{
QString modeval;
if ((perm & S_IFMT) == S_IFDIR) {
modeval.append(QLatin1Char('d'));
} else if ((perm & S_IFMT) == S_IFLNK) {
modeval.append(QLatin1Char('l'));
} else {
modeval.append(QLatin1Char('-'));
}
modeval.append((perm & S_IRUSR) ? QLatin1Char('r') : QLatin1Char('-'));
modeval.append((perm & S_IWUSR) ? QLatin1Char('w') : QLatin1Char('-'));
if ((perm & S_ISUID) && (perm & S_IXUSR)) {
modeval.append(QLatin1Char('s'));
} else if ((perm & S_ISUID)) {
modeval.append(QLatin1Char('S'));
} else if ((perm & S_IXUSR)) {
modeval.append(QLatin1Char('x'));
} else {
modeval.append(QLatin1Char('-'));
}
modeval.append((perm & S_IRGRP) ? QLatin1Char('r') : QLatin1Char('-'));
modeval.append((perm & S_IWGRP) ? QLatin1Char('w') : QLatin1Char('-'));
if ((perm & S_ISGID) && (perm & S_IXGRP)) {
modeval.append(QLatin1Char('s'));
} else if ((perm & S_ISGID)) {
modeval.append(QLatin1Char('S'));
} else if ((perm & S_IXGRP)) {
modeval.append(QLatin1Char('x'));
} else {
modeval.append(QLatin1Char('-'));
}
modeval.append((perm & S_IROTH) ? QLatin1Char('r') : QLatin1Char('-'));
modeval.append((perm & S_IWOTH) ? QLatin1Char('w') : QLatin1Char('-'));
if ((perm & S_ISVTX) && (perm & S_IXOTH)) {
modeval.append(QLatin1Char('t'));
} else if ((perm & S_ISVTX)) {
modeval.append(QLatin1Char('T'));
} else if ((perm & S_IXOTH)) {
modeval.append(QLatin1Char('x'));
} else {
modeval.append(QLatin1Char('-'));
}
return modeval;
}
QString LibzipPlugin::fromUnixSeparator(const QString& path)
{
if (!m_backslashedZip) {
......
......@@ -39,7 +39,6 @@ private:
bool writeEntry(zip_t *archive, const QString &entry, const Archive::Entry* destination, const CompressionOptions& options, bool isDir = false);
bool emitEntryForIndex(zip_t *archive, qlonglong index);
void emitProgress(double percentage);
QString permissionsToString(mode_t perm);
QString fromUnixSeparator(const QString& path);
QString toUnixSeparator(const QString& path);
static void progressCallback(zip_t *, double progress, void *that);
......
Supports Markdown
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