return __pakfire_cache_path(repo->pakfire, path, length, "%s/%s", name, buffer);
}
-#define pakfire_repo_relpath(repo, result, path) \
- __pakfire_repo_relpath(repo, result, sizeof(result), path);
-
-static int __pakfire_repo_relpath(struct pakfire_repo* self, char* result, size_t length, const char* path) {
- // Fetch the repo's base path
- const char* basepath = pakfire_repo_get_path(self);
-
- return __pakfire_path_relative(result, length, basepath, path);
-}
-
static int pakfire_repo_xfer_create(struct pakfire_xfer** xfer, struct pakfire_repo* repo,
const char* url, ...) __attribute__((format(printf, 3, 4)));
return id;
}
-int pakfire_repo_import_archive(struct pakfire_repo* self,
- struct pakfire_archive* archive, struct pakfire_package** package) {
- struct pakfire_package* pkg = NULL;
+int __pakfire_repo_make_path(struct pakfire_repo* self, char* path, size_t length,
+ struct pakfire_archive* archive, struct pakfire_package* pkg) {
const char* uuid = NULL;
- char relpath[PATH_MAX];
- char path[PATH_MAX];
- int r;
-
- // Add the metadata
- r = pakfire_archive_make_package(archive, self, &pkg);
- if (r < 0)
- goto ERROR;
// Fetch NEVRA
const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA);
// Fetch the filename this package should have
const char* filename = pakfire_package_get_filename(pkg);
if (!filename)
- return -EINVAL;
+ return -ENODATA;
// Compose the destination path
switch (self->appdata->fs_layout) {
case PAKFIRE_REPO_FLAT:
- r = pakfire_repo_path(self, path, "%s", filename);
- if (r < 0)
- goto ERROR;
- break;
+ return __pakfire_repo_path(self, path, length, "%s", filename);
case PAKFIRE_REPO_UUID:
// Fetch the UUID
uuid = pakfire_package_get_string(pkg, PAKFIRE_PKG_UUID);
if (!uuid) {
ERROR(self->ctx, "%s does not have a UUID\n", nevra);
- r = -EINVAL;
- goto ERROR;
+ return -ENODATA;
}
- r = pakfire_repo_path(self, path, "%s/%s", uuid, filename);
- if (r < 0)
- goto ERROR;
- break;
+ return __pakfire_repo_path(self, path, length, "%s/%s", uuid, filename);
// In virtual mode, we don't actually import the file
case PAKFIRE_REPO_VIRT:
- goto END;
+ return __pakfire_string_set(path, length, pakfire_archive_get_path(archive));
}
- // Compose the path of the archive relative to the repository path
- r = pakfire_repo_relpath(self, relpath, path);
- if (r < 0)
- goto ERROR;
+ return -EINVAL;
+}
- // Copy (or link) the archive
- r = pakfire_archive_link_or_copy(archive, path);
- if (r < 0)
- goto ERROR;
+int pakfire_repo_import_archive(struct pakfire_repo* self,
+ struct pakfire_archive* archive, struct pakfire_package** package) {
+ struct pakfire_package* pkg = NULL;
+ char path[PATH_MAX];
+ int r;
- // Reset the path
- r = pakfire_package_set_string(pkg, PAKFIRE_PKG_PATH, relpath);
+ // This only works on internal or local repositories
+ if (!pakfire_repo_is_internal(self) && !pakfire_repo_is_local(self))
+ return -ENOTSUP;
+
+ // Add the metadata
+ r = pakfire_archive_make_package(archive, self, &pkg);
if (r < 0)
goto ERROR;
-END:
+ // Fetch package path
+ const char* arc_path = pakfire_archive_get_path(archive);
+ const char* pkg_path = pakfire_package_get_path(pkg);
+
+ // Copy (or link) the archive
+ if (!pakfire_string_equals(arc_path, pkg_path)) {
+ r = pakfire_archive_link_or_copy(archive, path);
+ if (r < 0)
+ goto ERROR;
+ }
+
// Return the package if requested
if (package)
*package = pakfire_package_ref(pkg);
int pakfire_repo_internalize(struct pakfire_repo* repo, int flags);
Id pakfire_repo_add_solvable(struct pakfire_repo* repo);
+#define pakfire_repo_make_path(repo, path, archive, pkg) \
+ __pakfire_repo_make_path(repo, path, sizeof(path), archive, pkg)
+int __pakfire_repo_make_path(struct pakfire_repo* self,
+ char* path, size_t length, struct pakfire_archive* archive, struct pakfire_package* pkg);
+
int pakfire_repo_import_archive(struct pakfire_repo* self,
struct pakfire_archive* archive, struct pakfire_package** package);