From 1babcd2aa486ead1127c21fff15abee4c48a2c33 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 27 Jul 2020 10:57:15 +0200 Subject: [PATCH] [libcalamares] Put Permissions in CalamaresUtils namespace - most of the things in utils/ are in the CalamaresUtils namespace, let Permissions follow suit. Chase the name change in the *preservefiles* module. - add an `apply()` function for doing the most basic of chmod. Note that we don't use `QFile::setPermissions()` because the **values** used are different (0755 for chmod is 0x755 in the enum value passed to `setPermissions()`). --- src/libcalamares/utils/Permissions.cpp | 14 ++++++++++++++ src/libcalamares/utils/Permissions.h | 8 ++++++++ src/modules/preservefiles/PreserveFiles.cpp | 4 ++-- src/modules/preservefiles/PreserveFiles.h | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/libcalamares/utils/Permissions.cpp b/src/libcalamares/utils/Permissions.cpp index 3166d840a..3f5350e86 100644 --- a/src/libcalamares/utils/Permissions.cpp +++ b/src/libcalamares/utils/Permissions.cpp @@ -8,9 +8,14 @@ #include "Permissions.h" +#include + #include #include +namespace CalamaresUtils +{ + Permissions::Permissions() : m_username() , m_group() @@ -64,3 +69,12 @@ Permissions::parsePermissions( QString const& p ) return; } + +bool +Permissions::apply( const QString& path, int mode ) +{ + int r = chmod( path.toUtf8().constData(), mode ); + return r == 0; +} + +} // namespace CalamaresUtils diff --git a/src/libcalamares/utils/Permissions.h b/src/libcalamares/utils/Permissions.h index b6e2d3a44..913d037d5 100644 --- a/src/libcalamares/utils/Permissions.h +++ b/src/libcalamares/utils/Permissions.h @@ -13,6 +13,9 @@ #include +namespace CalamaresUtils +{ + /** * @brief The Permissions class takes a QString @p in the form of * ::, checks it for validity, and makes the three @@ -56,6 +59,9 @@ public: */ QString octal() const { return QString::number( value(), 8 ); } + /// chmod(path, mode), returns true on success + static bool apply( const QString& path, int mode ); + private: void parsePermissions( QString const& p ); @@ -65,4 +71,6 @@ private: bool m_valid; }; +} // namespace CalamaresUtils + #endif // LIBCALAMARES_PERMISSIONS_H diff --git a/src/modules/preservefiles/PreserveFiles.cpp b/src/modules/preservefiles/PreserveFiles.cpp index 3e34024e7..57c2c5422 100644 --- a/src/modules/preservefiles/PreserveFiles.cpp +++ b/src/modules/preservefiles/PreserveFiles.cpp @@ -220,7 +220,7 @@ PreserveFiles::setConfigurationMap( const QVariantMap& configurationMap ) { QString filename = li.toString(); if ( !filename.isEmpty() ) - m_items.append( Item { filename, filename, Permissions( defaultPermissions ), ItemType::Path } ); + m_items.append( Item { filename, filename, CalamaresUtils::Permissions( defaultPermissions ), ItemType::Path } ); else { cDebug() << "Empty filename for preservefiles, item" << c; @@ -248,7 +248,7 @@ PreserveFiles::setConfigurationMap( const QVariantMap& configurationMap ) } else { - m_items.append( Item { QString(), dest, Permissions( perm ), t } ); + m_items.append( Item { QString(), dest, CalamaresUtils::Permissions( perm ), t } ); } } else diff --git a/src/modules/preservefiles/PreserveFiles.h b/src/modules/preservefiles/PreserveFiles.h index 214ff0df8..fdba933fa 100644 --- a/src/modules/preservefiles/PreserveFiles.h +++ b/src/modules/preservefiles/PreserveFiles.h @@ -34,7 +34,7 @@ class PLUGINDLLEXPORT PreserveFiles : public Calamares::CppJob { QString source; QString dest; - Permissions perm; + CalamaresUtils::Permissions perm; ItemType type; };