From: Michael Tremer Date: Fri, 19 Mar 2021 19:10:28 +0000 (+0000) Subject: libpakfire: Move IPFire check X-Git-Tag: 0.9.28~1285^2~502 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=40db10e312a743da693de5a84dc3b9230a875de5;p=pakfire.git libpakfire: Move IPFire check Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index ff6dc69dc..5c27032ce 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -147,6 +147,25 @@ static void pakfire_free(Pakfire pakfire) { free(pakfire); } +// Safety check in case this is being launched on the host system +static int pakfire_safety_checks(Pakfire pakfire) { + // Nothing to do if we are not working on root + if (strcmp(pakfire->path, "/") != 0) + return 0; + + char* path = pakfire_make_path(pakfire, "/etc/ipfire-release"); + if (!path) + return 1; + + if (!pakfire_path_exists(path)) { + ERROR(pakfire, "Not an IPFire system\n"); + errno = EPERM; + return 1; + } + + return 0; +} + PAKFIRE_EXPORT int pakfire_create(Pakfire* pakfire, const char* path, const char* arch) { int r; @@ -205,6 +224,11 @@ PAKFIRE_EXPORT int pakfire_create(Pakfire* pakfire, const char* path, const char DEBUG(p, " arch = %s\n", pakfire_get_arch(p)); DEBUG(p, " path = %s\n", pakfire_get_path(p)); + // Perform some safety checks + r = pakfire_safety_checks(p); + if (r) + goto ERROR; + // Make sure that our private directory exists char* private_dir = pakfire_make_path(p, PAKFIRE_PRIVATE_DIR); r = pakfire_mkdir(p, private_dir, 0); diff --git a/src/pakfire/base.py b/src/pakfire/base.py index e59b1501a..0d0a0dab7 100644 --- a/src/pakfire/base.py +++ b/src/pakfire/base.py @@ -49,10 +49,6 @@ class Pakfire(_pakfire.Pakfire): # Default to system distribution self.distro = distro or system.distro - # check if we are actually running on an ipfire system - if self.path == "/": - self.check_is_ipfire() - # Load configuration self.config = config or Config("general.conf") @@ -106,12 +102,6 @@ class Pakfire(_pakfire.Pakfire): for repo in self.repos: repo.refresh(force=force) - def check_is_ipfire(self): - ret = os.path.exists("/etc/ipfire-release") - - if not ret: - raise NotIPFireError("You can run pakfire only on an IPFire system") - def clean(self): # Clean up repository caches for repo in self.repos: diff --git a/src/pakfire/errors.py b/src/pakfire/errors.py index ad33975e4..bc7ecfb27 100644 --- a/src/pakfire/errors.py +++ b/src/pakfire/errors.py @@ -65,9 +65,6 @@ class FileError(Error): class FileNotFoundError(Error): pass -class NotIPFireError(Error): - pass - class OfflineModeError(Error): message = _("The requested action cannot be done on offline mode.\n" "Please connect your system to the network, remove --offline from the"