mirror of
https://github.com/parchlinux/calamares.git
synced 2025-07-06 13:55:36 -04:00
- 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()`).
80 lines
1.4 KiB
C++
80 lines
1.4 KiB
C++
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
|
*
|
|
* SPDX-FileCopyrightText: 2018 Scott Harvey <scott@spharvey.me>
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
* License-Filename: LICENSE
|
|
*
|
|
*/
|
|
|
|
#include "Permissions.h"
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <QString>
|
|
#include <QStringList>
|
|
|
|
namespace CalamaresUtils
|
|
{
|
|
|
|
Permissions::Permissions()
|
|
: m_username()
|
|
, m_group()
|
|
, m_value( 0 )
|
|
, m_valid( false )
|
|
{
|
|
}
|
|
|
|
|
|
Permissions::Permissions( QString const& p )
|
|
: Permissions()
|
|
{
|
|
parsePermissions( p );
|
|
}
|
|
|
|
void
|
|
Permissions::parsePermissions( QString const& p )
|
|
{
|
|
|
|
QStringList segments = p.split( ":" );
|
|
|
|
if ( segments.length() != 3 )
|
|
{
|
|
m_valid = false;
|
|
return;
|
|
}
|
|
|
|
if ( segments[ 0 ].isEmpty() || segments[ 1 ].isEmpty() )
|
|
{
|
|
m_valid = false;
|
|
return;
|
|
}
|
|
|
|
bool ok;
|
|
int octal = segments[ 2 ].toInt( &ok, 8 );
|
|
if ( !ok || octal == 0 )
|
|
{
|
|
m_valid = false;
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
m_value = octal;
|
|
}
|
|
|
|
// We have exactly three segments and the third is valid octal,
|
|
// so we can declare the string valid and set the user and group names
|
|
m_valid = true;
|
|
m_username = segments[ 0 ];
|
|
m_group = segments[ 1 ];
|
|
|
|
return;
|
|
}
|
|
|
|
bool
|
|
Permissions::apply( const QString& path, int mode )
|
|
{
|
|
int r = chmod( path.toUtf8().constData(), mode );
|
|
return r == 0;
|
|
}
|
|
|
|
} // namespace CalamaresUtils
|