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;
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);
# 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")
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:
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"