[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()`).
This commit is contained in:
parent
409ab6ee86
commit
1babcd2aa4
@ -8,9 +8,14 @@
|
|||||||
|
|
||||||
#include "Permissions.h"
|
#include "Permissions.h"
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
|
||||||
Permissions::Permissions()
|
Permissions::Permissions()
|
||||||
: m_username()
|
: m_username()
|
||||||
, m_group()
|
, m_group()
|
||||||
@ -64,3 +69,12 @@ Permissions::parsePermissions( QString const& p )
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
Permissions::apply( const QString& path, int mode )
|
||||||
|
{
|
||||||
|
int r = chmod( path.toUtf8().constData(), mode );
|
||||||
|
return r == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace CalamaresUtils
|
||||||
|
@ -13,6 +13,9 @@
|
|||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The Permissions class takes a QString @p in the form of
|
* @brief The Permissions class takes a QString @p in the form of
|
||||||
* <user>:<group>:<permissions>, checks it for validity, and makes the three
|
* <user>:<group>:<permissions>, checks it for validity, and makes the three
|
||||||
@ -56,6 +59,9 @@ public:
|
|||||||
*/
|
*/
|
||||||
QString octal() const { return QString::number( value(), 8 ); }
|
QString octal() const { return QString::number( value(), 8 ); }
|
||||||
|
|
||||||
|
/// chmod(path, mode), returns true on success
|
||||||
|
static bool apply( const QString& path, int mode );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void parsePermissions( QString const& p );
|
void parsePermissions( QString const& p );
|
||||||
|
|
||||||
@ -65,4 +71,6 @@ private:
|
|||||||
bool m_valid;
|
bool m_valid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace CalamaresUtils
|
||||||
|
|
||||||
#endif // LIBCALAMARES_PERMISSIONS_H
|
#endif // LIBCALAMARES_PERMISSIONS_H
|
||||||
|
@ -220,7 +220,7 @@ PreserveFiles::setConfigurationMap( const QVariantMap& configurationMap )
|
|||||||
{
|
{
|
||||||
QString filename = li.toString();
|
QString filename = li.toString();
|
||||||
if ( !filename.isEmpty() )
|
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
|
else
|
||||||
{
|
{
|
||||||
cDebug() << "Empty filename for preservefiles, item" << c;
|
cDebug() << "Empty filename for preservefiles, item" << c;
|
||||||
@ -248,7 +248,7 @@ PreserveFiles::setConfigurationMap( const QVariantMap& configurationMap )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_items.append( Item { QString(), dest, Permissions( perm ), t } );
|
m_items.append( Item { QString(), dest, CalamaresUtils::Permissions( perm ), t } );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -34,7 +34,7 @@ class PLUGINDLLEXPORT PreserveFiles : public Calamares::CppJob
|
|||||||
{
|
{
|
||||||
QString source;
|
QString source;
|
||||||
QString dest;
|
QString dest;
|
||||||
Permissions perm;
|
CalamaresUtils::Permissions perm;
|
||||||
ItemType type;
|
ItemType type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user