pakfire_package_set_build_time(self->package, build_time);
}
-static PyObject* Package_get_cache_path(PackageObject* self) {
- char* cache_path = pakfire_package_get_cache_path(self->package);
- PyObject* ret = PyUnicode_FromString(cache_path);
- free(cache_path);
-
- return ret;
-}
-
static PyObject* Package_get_repo(PackageObject* self) {
PakfireRepo repo = pakfire_package_get_repo(self->package);
if (!repo)
return obj;
}
-static PyObject* Package_get_location(PackageObject* self) {
- char* location = pakfire_package_get_location(self->package);
-
- PyObject* str = PyUnicode_FromString(location);
- free(location);
+static PyObject* Package_get_path(PackageObject* self) {
+ const char* path = pakfire_package_get_path(self->package);
+ if (!path) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ return NULL;
+ }
- return str;
+ return PyUnicode_FromString(path);
}
static PyObject* PyList_FromRelationList(PakfireRelationList relationlist) {
NULL,
NULL
},
- {
- "cache_path",
- (getter)Package_get_cache_path,
- NULL,
- NULL,
- NULL
- },
// Dependencies
{
NULL
},
{
- "location",
- (getter)Package_get_location,
+ "path",
+ (getter)Package_get_path,
NULL,
NULL,
NULL
const char* pakfire_package_get_maintainer(PakfirePackage pkg);
void pakfire_package_set_maintainer(PakfirePackage pkg, const char* maintainer);
const char* pakfire_package_get_filename(PakfirePackage pkg);
+const char* pakfire_package_get_path(PakfirePackage pkg);
+void pakfire_package_set_path(PakfirePackage pkg, const char* path);
void pakfire_package_set_filename(PakfirePackage pkg, const char* filename);
int pakfire_package_is_installed(PakfirePackage pkg);
unsigned long long pakfire_package_get_downloadsize(PakfirePackage pkg);
PakfireRepo pakfire_package_get_repo(PakfirePackage pkg);
-char* pakfire_package_get_location(PakfirePackage pkg);
-
char* pakfire_package_dump(PakfirePackage pkg, int flags);
PakfireArchive pakfire_package_get_archive(PakfirePackage pkg);
-int pakfire_package_is_cached(PakfirePackage pkg);
-char* pakfire_package_get_cache_path(PakfirePackage pkg);
-char* pakfire_package_get_cache_full_path(PakfirePackage pkg);
-
PakfireFilelist pakfire_package_get_filelist(PakfirePackage pkg);
int pakfire_package_set_filelist(PakfirePackage pkg, PakfireFilelist filelist);
int pakfire_package_set_filelist_from_string(PakfirePackage pkg, const char* files);
Id id;
int nrefs;
+ char filename[NAME_MAX];
+ char path[PATH_MAX];
PakfireRepo repo;
};
pakfire_package_set_string(pkg, SOLVABLE_PACKAGER, maintainer);
}
+static int pakfire_package_make_cache_path(PakfirePackage pkg) {
+ const char* filename = pakfire_package_get_filename(pkg);
+ const char* checksum = pakfire_package_get_checksum(pkg);
+
+ if (strlen(checksum) < 3)
+ return 1;
+
+ return pakfire_make_cache_path(pkg->pakfire, pkg->path,
+ "%c%c/%s/%s", checksum[0], checksum[1], checksum + 2, filename);
+}
+
+PAKFIRE_EXPORT const char* pakfire_package_get_path(PakfirePackage pkg) {
+ int r;
+
+ if (!*pkg->path) {
+ const char* base = pakfire_package_get_string(pkg, SOLVABLE_MEDIABASE);
+ if (base) {
+ const char* filename = pakfire_package_get_filename(pkg);
+ if (!filename)
+ return NULL;
+
+ pakfire_string_format(pkg->path, "%s/%s", base, filename);
+ } else {
+ r = pakfire_package_make_cache_path(pkg);
+ if (r)
+ return NULL;
+ }
+ }
+
+ return pkg->path;
+}
+
+PAKFIRE_EXPORT void pakfire_package_set_path(PakfirePackage pkg, const char* path) {
+ char* basename = pakfire_basename(path);
+ char* dirname = pakfire_dirname(path);
+
+ if (basename) {
+ pakfire_package_set_string(pkg, SOLVABLE_MEDIAFILE, basename);
+ free(basename);
+ }
+
+ if (dirname) {
+ pakfire_package_set_string(pkg, SOLVABLE_MEDIABASE, dirname);
+ free(dirname);
+ }
+
+ pakfire_string_set(pkg->path, path);
+}
+
+// Removes epoch
+static const char* evr2vr(const char* evr) {
+ const char* p = evr;
+
+ // Skip any leading digits
+ for (; *p >= '0' && *p <= '9'; p++);
+
+ // If after the leading digits, we found :, we return the rest of the string
+ if (p != evr && *p == ':')
+ return ++p;
+
+ return evr;
+}
+
+static const char* pakfire_package_make_filename(PakfirePackage pkg) {
+ if (!*pkg->filename) {
+ const char* name = pakfire_package_get_name(pkg);
+ const char* evr = pakfire_package_get_evr(pkg);
+ const char* arch = pakfire_package_get_arch(pkg);
+
+ if (!name || !evr || !arch)
+ return NULL;
+
+ const char* vr = evr2vr(evr);
+
+ pakfire_string_format(pkg->filename, "%s-%s.%s.pfm", name, vr, arch);
+ }
+
+ return pkg->filename;
+}
+
PAKFIRE_EXPORT const char* pakfire_package_get_filename(PakfirePackage pkg) {
- return pakfire_package_get_string(pkg, SOLVABLE_MEDIAFILE);
+ const char* filename = pakfire_package_get_string(pkg, SOLVABLE_MEDIAFILE);
+
+ // Generate the filename if not set
+ if (!filename)
+ filename = pakfire_package_make_filename(pkg);
+
+ return filename;
}
PAKFIRE_EXPORT void pakfire_package_set_filename(PakfirePackage pkg, const char* filename) {
return pakfire_repo_ref(pkg->repo);
}
-PAKFIRE_EXPORT void pakfire_package_set_repo(PakfirePackage pkg, PakfireRepo repo) {
- // Free old repository
- if (pkg->repo)
- pakfire_repo_unref(pkg->repo);
-
- Solvable* s = get_solvable(pkg);
- s->repo = pakfire_repo_get_repo(repo);
-
- pkg->repo = pakfire_repo_ref(repo);
-}
-
-PAKFIRE_EXPORT char* pakfire_package_get_location(PakfirePackage pkg) {
- pakfire_package_internalize_repo(pkg);
-
- Solvable* s = get_solvable(pkg);
-
- const char* location = solvable_get_location(s, NULL);
- return strdup(location);
-}
-
static void pakfire_package_dump_add_line(char** str, const char* key, const char* val) {
if (val)
asprintf(str, "%s%-15s: %s\n", *str, key ? key : "", val);
return string;
}
-PAKFIRE_EXPORT int pakfire_package_is_cached(PakfirePackage pkg) {
- char* path = pakfire_package_get_cache_path(pkg);
-
- // Check if the file is readable
- int r = access(path, R_OK);
- free(path);
-
- return (r == 0);
-}
-
-PAKFIRE_EXPORT char* pakfire_package_get_cache_path(PakfirePackage pkg) {
- char path[PATH_MAX];
-
- const char* filename = pakfire_package_get_filename(pkg);
- const char* checksum = pakfire_package_get_checksum(pkg);
-
- if (strlen(checksum) < 3)
- return NULL;
-
- pakfire_make_cache_path(pkg->pakfire, path,
- "%c%c/%s/%s", checksum[0], checksum[1], checksum + 2, filename);
-
- return strdup(path);
-}
-
PAKFIRE_EXPORT PakfireArchive pakfire_package_get_archive(PakfirePackage pkg) {
+ PakfireArchive archive;
+
// Otherwise open the archive from the cache
- char* path = pakfire_package_get_cache_path(pkg);
+ const char* path = pakfire_package_get_path(pkg);
if (!path)
return NULL;
- PakfireArchive archive = NULL;
-
// Open archive
int r = pakfire_archive_open(&archive, pkg->pakfire, path);
- free(path);
if (r == 0)
return archive;