static FILE* pakfire_archive_clone_file(struct pakfire_archive* archive) {
int fd = fileno(archive->f);
if (fd < 0) {
- ERROR(archive->pakfire, "Could not fetch the archive's file descriptor: %m\n");
+ CTX_ERROR(archive->ctx, "Could not fetch the archive's file descriptor: %m\n");
return NULL;
}
// Duplicate the file descriptor
fd = dup(fd);
if (fd < 0) {
- ERROR(archive->pakfire, "Could not duplicate the file descriptor: %m\n");
+ CTX_ERROR(archive->ctx, "Could not duplicate the file descriptor: %m\n");
return NULL;
}
r = pakfire_digests_compute_from_file(archive->ctx, &archive->digests,
PAKFIRE_ARCHIVE_CHECKSUM, archive->f);
if (r)
- ERROR(archive->pakfire, "Could not calculate digest of %s: %m\n", archive->path);
+ CTX_ERROR(archive->ctx, "Could not calculate digest of %s: %m\n", archive->path);
return r;
}
// Try opening the archive file
int r = archive_read_open_FILE(a, f);
if (r) {
- ERROR(archive->pakfire, "Could not open archive %s: %s\n",
+ CTX_ERROR(archive->ctx, "Could not open archive %s: %s\n",
archive->path, archive_error_string(a));
goto ERROR;
}
// Create tokener
struct json_tokener* tokener = json_tokener_new();
if (!tokener) {
- ERROR(archive->pakfire, "Could not allocate JSON tokener: %m\n");
+ CTX_ERROR(archive->ctx, "Could not allocate JSON tokener: %m\n");
goto ERROR;
}
if (!archive->metadata) {
enum json_tokener_error error = json_tokener_get_error(tokener);
- ERROR(archive->pakfire, "JSON parsing error: %s\n",
+ CTX_ERROR(archive->ctx, "JSON parsing error: %s\n",
json_tokener_error_desc(error));
goto ERROR;
}
- DEBUG(archive->pakfire, "Successfully parsed package metadata:\n%s\n",
+ CTX_DEBUG(archive->ctx, "Successfully parsed package metadata:\n%s\n",
json_object_to_json_string_ext(archive->metadata,
JSON_C_TO_STRING_PRETTY|JSON_C_TO_STRING_PRETTY_TAB));
const char* data, const size_t length) {
// Check if format has already been set
if (archive->format) {
- ERROR(archive->pakfire, "Archive format has already been parsed\n");
+ CTX_ERROR(archive->ctx, "Archive format has already been parsed\n");
return -EINVAL;
}
// Break on anything else
default:
- ERROR(archive->pakfire, "This version of Pakfire does not support "
+ CTX_ERROR(archive->ctx, "This version of Pakfire does not support "
"archive format %u\n", archive->format);
return -ENOTSUP;
}
- DEBUG(archive->pakfire, "Archive format is %u\n", archive->format);
+ CTX_DEBUG(archive->ctx, "Archive format is %u\n", archive->format);
return 0;
}
// Check for any available space
if (archive->num_scriptlets >= MAX_SCRIPTLETS) {
- ERROR(archive->pakfire, "Too many scriptlets\n");
+ CTX_ERROR(archive->ctx, "Too many scriptlets\n");
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);
+ CTX_ERROR(archive->ctx, "Could not determine the scriptlet type from '%s'\n", path);
return -EINVAL;
}
// 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");
+ CTX_ERROR(archive->ctx, "Trying to open an empty archive file\n");
return -EINVAL;
}
- DEBUG(archive->pakfire, "Reading archive metadata...\n");
+ CTX_DEBUG(archive->ctx, "Reading archive metadata...\n");
// Walk through the archive
r = pakfire_archive_walk(archive, __pakfire_archive_read_metadata,
// Check if we could successfully read something
if (!archive->format) {
- ERROR(archive->pakfire, "Archive has an unknown format\n");
+ CTX_ERROR(archive->ctx, "Archive has an unknown format\n");
return -ENOMSG;
}
// Check if we have read some metadata
if (!archive->metadata) {
- ERROR(archive->pakfire, "Archive has no metadata\n");
+ CTX_ERROR(archive->ctx, "Archive has no metadata\n");
return -ENOMSG;
}
if (!path)
return -EINVAL;
- DEBUG(archive->pakfire, "Opening archive %s\n", path);
+ CTX_DEBUG(archive->ctx, "Opening archive %s\n", path);
// Store path
pakfire_string_set(archive->path, path);
// Let the kernel know, that we will read the file sequentially
r = posix_fadvise(fileno(archive->f), 0, 0, POSIX_FADV_SEQUENTIAL);
if (r) {
- ERROR(archive->pakfire, "posix_fadvise() failed: %m\n");
+ CTX_ERROR(archive->ctx, "posix_fadvise() failed: %m\n");
goto ERROR;
}
// Call stat() on f
r = fstat(fileno(archive->f), &archive->stat);
if (r) {
- ERROR(archive->pakfire, "Could not stat archive: %m\n");
+ CTX_ERROR(archive->ctx, "Could not stat archive: %m\n");
goto ERROR;
}
// Read all package metadata
r = pakfire_archive_read_metadata(archive);
if (r) {
- ERROR_ERRNO(archive->pakfire, r, "Could not open archive: %m\n");
+ CTX_ERROR(archive->ctx, "Could not open archive: %s\n", strerror(-r));
goto ERROR;
}
// Try finding a matching JSON object
r = json_object_object_get_ex(object, *key, &object);
if (!r) {
- DEBUG(archive->pakfire, "Could not find JSON object at '%s': %m\n", *key);
+ CTX_DEBUG(archive->ctx, "Could not find JSON object at '%s': %m\n", *key);
break;
}
}
// Allocate a cookie
cookie = calloc(1, sizeof(*cookie));
if (!cookie) {
- ERROR(archive->pakfire, "Could not allocate a cookie: %m\n");
+ CTX_ERROR(archive->ctx, "Could not allocate a cookie: %m\n");
goto ERROR;
}
// Store the path
r = pakfire_string_set(cookie->path, path);
if (r) {
- ERROR(archive->pakfire, "Could not set path: %m\n");
+ CTX_ERROR(archive->ctx, "Could not set path: %m\n");
goto ERROR;
}
// Clone the archive file descriptor to read the file independently
cookie->f = pakfire_archive_clone_file(archive);
if (!cookie->f) {
- ERROR(archive->pakfire, "Could not duplicate file descriptor for %s: %m\n",
+ CTX_ERROR(archive->ctx, "Could not duplicate file descriptor for %s: %m\n",
archive->path);
goto ERROR;
}
// Nothing found
if (!cookie->__f) {
- ERROR(archive->pakfire, "Could not find /%s\n", path);
+ CTX_ERROR(archive->ctx, "Could not find /%s\n", path);
// No such file or directory
errno = ENOENT;
if (size < 0)
return -EINVAL;
- DEBUG(archive->pakfire, "Copying %s to %s...\n", archive->path, path);
+ CTX_DEBUG(archive->ctx, "Copying %s to %s...\n", archive->path, path);
// Ensure we copy from the very beginning
rewind(archive->f);
// Copy everything
ssize_t bytes_written = sendfile(fileno(f), fileno(archive->f), NULL, size);
if (bytes_written < size) {
- ERROR(archive->pakfire, "Could not copy archive (%zd byte(s) written): %m\n",
+ CTX_ERROR(archive->ctx, "Could not copy archive (%zd byte(s) written): %m\n",
bytes_written);
goto ERROR;
}
if (!path)
return -EINVAL;
- DEBUG(archive->pakfire, "Linking %s to %s...\n", archive->path, path);
+ CTX_DEBUG(archive->ctx, "Linking %s to %s...\n", archive->path, path);
// Delete the destination file (if it exists)
unlink(path);
// Create the new link
r = link(archive->path, path);
if (r) {
- DEBUG(archive->pakfire, "Could not create hardlink %s: %m\n", path);
+ CTX_DEBUG(archive->ctx, "Could not create hardlink %s: %m\n", path);
return r;
}
// Fetch NEVRA
const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA);
- DEBUG(archive->pakfire, "Extracting %s\n", archive->path);
+ CTX_DEBUG(archive->ctx, "Extracting %s\n", archive->path);
// Copy everything to path if set
if (path) {
char* expected_hexdigest = __pakfire_hexlify(digest, length);
char* computed_hexdigest = __pakfire_hexlify(computed_digest, computed_length);
- ERROR(archive->pakfire, "Archive digest does not match for %s:\n", archive->path);
- ERROR(archive->pakfire, " Expected: %s\n", expected_hexdigest);
- ERROR(archive->pakfire, " Computed: %s\n", computed_hexdigest);
+ CTX_ERROR(archive->ctx, "Archive digest does not match for %s:\n", archive->path);
+ CTX_ERROR(archive->ctx, " Expected: %s\n", expected_hexdigest);
+ CTX_ERROR(archive->ctx, " Computed: %s\n", computed_hexdigest);
if (expected_hexdigest)
free(expected_hexdigest);
// Fetch the array with the filelist
array = pakfire_archive_metadata_get_object(archive, "filelist", NULL);
if (!array) {
- ERROR(archive->pakfire, "Archive has no filelist: %m\n");
+ CTX_ERROR(archive->ctx, "Archive has no filelist: %m\n");
return 1;
}
#ifdef ENABLE_DEBUG
const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA);
- DEBUG(archive->pakfire, "Created package %s (%p) from archive %p\n",
+ CTX_DEBUG(archive->ctx, "Created package %s (%p) from archive %p\n",
nevra, pkg, archive);
#endif