Skip to content

Commit

Permalink
Make sure we have write permission if we want to import packages
Browse files Browse the repository at this point in the history
This is not perfect as the permissions might change between this check
and the actual system state writing.
  • Loading branch information
kontura authored and j-mracek committed Dec 15, 2023
1 parent 699221f commit bd55cba
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libdnf5/system/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "libdnf5/utils/bgettext/bgettext-mark-domain.h"
#include "libdnf5/utils/fs/file.hpp"
#include "libdnf5/utils/fs/temp.hpp"

#include <libdnf5/comps/group/package.hpp>
#include <toml.hpp>
Expand Down Expand Up @@ -247,6 +248,13 @@ State::State(const std::filesystem::path & path) : path(path) {


bool State::packages_import_required() {
// Importing will require write permission
try {
utils::fs::TempFile(path, "permissions-test");
} catch (const FileSystemError & e) {
return false;
}

// TODO(mblaha) - detect by absence of toml file instead of empty nevra_states?
// Because even empty nevra_states is a valid state.
return nevra_states.empty();
Expand Down

0 comments on commit bd55cba

Please sign in to comment.