char filename[NAME_MAX];
char path[PATH_MAX];
char cache_path[PATH_MAX];
+ char local_path[PATH_MAX];
struct {
pcre2_code* requires;
return pkg->filename;
}
+static int pakfire_package_make_path_internal(struct pakfire_package* self) {
+ const char* path = NULL;
+
+ // Fetch the path
+ path = pakfire_package_get_string(self, PAKFIRE_PKG_PATH);
+ if (!path)
+ return -EINVAL;
+
+ return pakfire_string_set(self->local_path, path);
+}
+
+static int pakfire_package_make_path_local(struct pakfire_package* self, struct pakfire_repo* repo) {
+ const char* path = NULL;
+
+ // Fetch the path
+ path = pakfire_package_get_string(self, PAKFIRE_PKG_PATH);
+ if (!path)
+ return -EINVAL;
+
+ // Compose path relative to the repository's base
+ return pakfire_repo_path(repo, self->local_path, "%s", path);
+}
+
+static int pakfire_package_make_path_cache(struct pakfire_package* self) {
+ const char* path = NULL;
+
+ // Fetch the cache path
+ path = pakfire_package_get_string(self, PAKFIRE_PKG_CACHE_PATH);
+ if (!path)
+ return -EINVAL;
+
+ return pakfire_string_set(self->local_path, path);
+}
+
+/*
+ Returns the path this package is or should be stored.
+*/
+const char* pakfire_package_get_path(struct pakfire_package* self) {
+ struct pakfire_repo* repo = NULL;
+ int r;
+
+ // Return the cached value if we have one
+ if (*self->local_path)
+ return self->local_path;
+
+ // Fetch NEVRA
+ const char* nevra = pakfire_package_get_string(self, PAKFIRE_PKG_NEVRA);
+
+ // Fetch the repository
+ repo = pakfire_package_get_repo(self);
+ if (!repo) {
+ ERROR(self->ctx, "Could not find repository for %s\n", nevra);
+ r = -ENOTSUP;
+ goto ERROR;
+ }
+
+ // For internal repositories, we return the stored path
+ if (pakfire_repo_is_internal(repo))
+ r = pakfire_package_make_path_internal(self);
+
+ // Check local repositories
+ else if (pakfire_repo_is_local(repo))
+ r = pakfire_package_make_path_local(self, repo);
+
+ // Everything else should be stored in the cache
+ else
+ r = pakfire_package_make_path_cache(self);
+
+ERROR:
+ if (repo)
+ pakfire_repo_unref(repo);
+
+ return (r == 0) ? self->local_path : NULL;
+}
+
static int pakfire_package_make_cache_path(struct pakfire_package* pkg) {
const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA);
return r;
}
-static int pakfire_package_is_available_exists(struct pakfire_package* self, const char* path) {
+/*
+ This function checks if the archive is available.
+*/
+int pakfire_package_is_available(struct pakfire_package* self) {
+ const char* path = NULL;
struct stat st = {};
int r;
+ // Fetch the path
+ path = pakfire_package_get_path(self);
+ if (!path)
+ return -EINVAL;
+
// Stat the path
r = stat(path, &st);
if (r < 0) {
return 1;
}
-static int pakfire_package_is_available_local(
- struct pakfire_package* self, struct pakfire_repo* repo) {
- char path[PATH_MAX];
- int r;
-
- const char* pkg_path = pakfire_package_get_string(self, PAKFIRE_PKG_PATH);
-
- // Compose path
- r = pakfire_repo_path(repo, path, "%s", pkg_path);
- if (r < 0) {
- ERROR(self->ctx, "Could not compose package path: %s\n", strerror(-r));
- return r;
- }
-
- // Check if the package actually exists
- return pakfire_package_is_available_exists(self, path);
-}
-
-static int pakfire_package_is_available_cache(struct pakfire_package* self) {
- // Fetch the path the package should be in the cache
- const char* path = pakfire_package_get_string(self, PAKFIRE_PKG_CACHE_PATH);
-
- // Check if the package actually exists
- return pakfire_package_is_available_exists(self, path);
-}
-
-/*
- This function checks if the archive is available.
-
- For local repositories, the path is checked, otherwise we will check the cache.
-*/
-int pakfire_package_is_available(struct pakfire_package* self) {
- struct pakfire_repo* repo = NULL;
- int r;
-
- // Fetch NEVRA
- const char* nevra = pakfire_package_get_string(self, PAKFIRE_PKG_NEVRA);
-
- // Fetch the repository
- repo = pakfire_package_get_repo(self);
- if (!repo) {
- ERROR(self->ctx, "Could not find repository for %s\n", nevra);
- r = -ENOTSUP;
- goto ERROR;
- }
-
- // Check local repositories
- if (pakfire_repo_is_local(repo)) {
- r = pakfire_package_is_available_local(self, repo);
- if (r < 0)
- goto ERROR;
-
- // Check remote repositories
- } else {
- r = pakfire_package_is_available_cache(self);
- if (r < 0)
- goto ERROR;
- }
-
-ERROR:
- if (repo)
- pakfire_repo_unref(repo);
-
- return r;
-}
-
int pakfire_package_is_installed(struct pakfire_package* pkg) {
Pool* pool = pakfire_get_solv_pool(pkg->pakfire);
Solvable* s = get_solvable(pkg);