if (!PyArg_ParseTuple(args, "O!s", &PakfireType, &pakfire, &filename))
return -1;
- int r = pakfire_archive_open(&self->archive, pakfire->pakfire, filename);
- if (r) {
+ errno = -pakfire_archive_open(&self->archive, pakfire->pakfire, filename);
+ if (errno) {
PyErr_SetFromErrno(PyExc_OSError);
return -1;
}
return NULL;
// Extract payload
- int r = pakfire_archive_extract(self->archive, path, flags);
- if (r) {
+ errno = -pakfire_archive_extract(self->archive, path, flags);
+ if (errno) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
// Check if format has already been set
if (archive->format) {
ERROR(archive->pakfire, "Archive format has already been parsed\n");
- errno = EINVAL;
- return 1;
+ return -EINVAL;
}
// Parse the format
default:
ERROR(archive->pakfire, "This version of Pakfire does not support "
"archive format %d\n", archive->format);
- errno = EINVAL;
- return 1;
+ return -EINVAL;
}
DEBUG(archive->pakfire, "Archive format is %d\n", archive->format);
// Check for any available space
if (archive->num_scriptlets >= MAX_SCRIPTLETS) {
ERROR(archive->pakfire, "Too many scriptlets\n");
- errno = ENOBUFS;
- return 1;
+ return -ENOBUFS;
}
// Determine type
type = pakfire_path_relpath(".scriptlets/", path);
if (!type) {
ERROR(archive->pakfire, "Could not determine the scriptlet type from '%s'\n", path);
- errno = EINVAL;
- return 1;
+ return -EINVAL;
}
// Allocate a scriptlet
// Check if the archive file actually has any contect
if (!archive->stat.st_size) {
ERROR(archive->pakfire, "Trying to open an empty archive file\n");
- errno = EINVAL;
- return 1;
+ return -EINVAL;
}
DEBUG(archive->pakfire, "Reading archive metadata...\n");
// Check if we could successfully read something
if (!archive->format) {
ERROR(archive->pakfire, "Archive has an unknown format\n");
- errno = EINVAL;
- return 1;
+ return -EINVAL;
}
// Check if we have read some metadata
if (!archive->metadata) {
ERROR(archive->pakfire, "Archive has no metadata\n");
- errno = EINVAL;
- return 1;
+ return -EINVAL;
}
return 0;
static int pakfire_archive_try_open(struct pakfire_archive* archive, const char* path) {
int r;
- if (!path) {
- errno = EINVAL;
- return 1;
- }
+ // Check inputs
+ if (!path)
+ return -EINVAL;
DEBUG(archive->pakfire, "Opening archive %s\n", path);
}
int pakfire_archive_copy(struct pakfire_archive* archive, const char* path) {
- if (!path) {
- errno = EINVAL;
- return 1;
- }
+ if (!path)
+ return -EINVAL;
// Determine the file size
ssize_t size = pakfire_archive_get_size(archive);
if (size < 0)
- return 1;
+ return -EINVAL;
DEBUG(archive->pakfire, "Copying %s to %s...\n", archive->path, path);
// Open destination file
FILE* f = fopen(path, "w");
if (!f)
- return 1;
+ return -errno;
int r = 1;
int r;
// Check if path is set
- if (!path) {
- errno = EINVAL;
- return 1;
- }
+ if (!path)
+ return -EINVAL;
DEBUG(archive->pakfire, "Linking %s to %s...\n", archive->path, path);
// Try to create a hardlink
r = pakfire_archive_link(archive, path);
- if (r) {
- switch (errno) {
- // Try to copy the file if we could not create a hardlink
- case EPERM:
- r = pakfire_archive_copy(archive, path);
+ switch (-r) {
+ // Try to copy the file if we could not create a hardlink
+ case EPERM:
+ r = pakfire_archive_copy(archive, path);
- default:
- break;
- }
+ default:
+ break;
}
return r;