// Create a new Pakfire instance
int r = pakfire_create(&self->pakfire, path, arch);
if (r) {
- switch (r) {
- // Invalid architecture
- case -EINVAL:
+ switch (errno) {
+ // Invalid architecture or path
+ case EINVAL:
PyErr_SetString(PyExc_ValueError, "Invalid architecture or path");
break;
// path does not exist
- case -ENOENT:
+ case ENOENT:
PyErr_Format(PyExc_FileNotFoundError,
"%s does not exist or is not a directory", path);
break;
// Anything else
default:
- PyErr_SetNone(PyExc_OSError);
+ PyErr_SetFromErrno(PyExc_OSError);
}
return -1;
// Check if the architecture is supported
if (!pakfire_arch_supported(arch)) {
- return -EINVAL;
+ errno = EINVAL;
+ return 1;
}
// Path must be absolute
if (!pakfire_string_startswith(path, "/")) {
- return -EINVAL;
+ errno = EINVAL;
+ return 1;
}
// Check if path exists
if (!pakfire_path_isdir(path)) {
- return -ENOENT;
+ errno = ENOENT;
+ return 1;
}
// Check if we are running as root
uid_t uid = getuid();
if (uid != 0) {
- return -EPERM;
+ errno = EPERM;
+ return 1;
}
Pakfire p = calloc(1, sizeof(*p));
if (!p)
- return -ENOMEM;
+ return 1;
p->nrefs = 1;
// Create a pakfire instance
r = pakfire_create(&t->pakfire, root, NULL);
if (r) {
- LOG("ERROR: Could not initialize Pakfire: %s\n", strerror(-r));
+ LOG("ERROR: Could not initialize Pakfire: %s\n", strerror(errno));
exit(1);
}