return r;
}
+static int pakfire_archive_link(struct pakfire_archive* archive, const char* path) {
+ int r;
+
+ // Check if path is set
+ if (!path) {
+ errno = EINVAL;
+ return 1;
+ }
+
+ DEBUG(archive->pakfire, "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);
+ return r;
+ }
+
+ return 0;
+}
+
+int pakfire_archive_link_or_copy(struct pakfire_archive* archive, const char* path) {
+ int r;
+
+ // 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);
+
+ default:
+ break;
+ }
+ }
+
+ return r;
+}
+
static int __pakfire_archive_extract(struct pakfire_archive* archive, int flags) {
struct pakfire_filelist* filelist = NULL;
struct pakfire_package* pkg = NULL;
#include <pakfire/pakfire.h>
int pakfire_archive_copy(struct pakfire_archive* archive, const char* path);
+int pakfire_archive_link_or_copy(struct pakfire_archive* archive, const char* path);
int pakfire_archive_check_digest(struct pakfire_archive* archive,
const enum pakfire_digest_types type, const unsigned char* digest, const size_t length);