/* === This file is part of Calamares - === * * SPDX-FileCopyrightText: 2018 Scott Harvey * SPDX-License-Identifier: GPL-3.0-or-later * License-Filename: LICENSE * */ #include "Permissions.h" #include #include #include 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