From 90a0605f38d5268b262998270426b293b0c946e0 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 27 Jul 2020 12:25:50 +0200 Subject: [PATCH] [preservefiles] [users] Use the Permissions methods - don't call out to tools (executables) when we have an API for it (which might call out to those tools, but that's abstracted) --- src/modules/preservefiles/PreserveFiles.cpp | 21 ++------------------- src/modules/users/CreateUserJob.cpp | 3 ++- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/src/modules/preservefiles/PreserveFiles.cpp b/src/modules/preservefiles/PreserveFiles.cpp index 57c2c5422..8352e861d 100644 --- a/src/modules/preservefiles/PreserveFiles.cpp +++ b/src/modules/preservefiles/PreserveFiles.cpp @@ -157,26 +157,9 @@ PreserveFiles::exec() { if ( it.perm.isValid() ) { - auto s_p = CalamaresUtils::System::instance(); - - int r; - - r = s_p->targetEnvCall( QStringList { "chown", it.perm.username(), bare_dest } ); - if ( r ) - { - cWarning() << "Could not chown target" << bare_dest; - } - - r = s_p->targetEnvCall( QStringList { "chgrp", it.perm.group(), bare_dest } ); - if ( r ) - { - cWarning() << "Could not chgrp target" << bare_dest; - } - - r = s_p->targetEnvCall( QStringList { "chmod", it.perm.octal(), bare_dest } ); - if ( r ) + if ( !it.perm.apply( CalamaresUtils::System::instance()->targetPath( bare_dest ) ) ) { - cWarning() << "Could not chmod target" << bare_dest; + cWarning() << "Could not set attributes of" << bare_dest; } } diff --git a/src/modules/users/CreateUserJob.cpp b/src/modules/users/CreateUserJob.cpp index f0b1dca88..84a42437a 100644 --- a/src/modules/users/CreateUserJob.cpp +++ b/src/modules/users/CreateUserJob.cpp @@ -12,6 +12,7 @@ #include "JobQueue.h" #include "utils/CalamaresUtilsSystem.h" #include "utils/Logger.h" +#include "utils/Permissions.h" #include #include @@ -103,7 +104,7 @@ CreateUserJob::exec() if ( fileResult ) { - if ( QProcess::execute( "chmod", { "440", fileResult.path() } ) ) + if ( CalamaresUtils::Permissions::apply( fileResult.path(), 0440 ) ) { return Calamares::JobResult::error( tr( "Cannot chmod sudoers file." ) ); }