src/libpakfire/include/pakfire/key.h \
src/libpakfire/include/pakfire/logging.h \
src/libpakfire/include/pakfire/package.h \
- src/libpakfire/include/pakfire/packagecache.h \
src/libpakfire/include/pakfire/packagelist.h \
src/libpakfire/include/pakfire/pakfire.h \
src/libpakfire/include/pakfire/pool.h \
return ret;
}
-static PyObject* Package_get_cache_full_path(PackageObject* self) {
- char* cache_path = pakfire_package_get_cache_full_path(self->package);
- PyObject* ret = PyUnicode_FromString(cache_path);
- pakfire_free(cache_path);
-
- return ret;
-}
-
static PyObject* Package_get_repo(PackageObject* self) {
PakfireRepo repo = pakfire_package_get_repo(self->package);
if (!repo)
NULL,
NULL
},
- {
- "cache_full_path",
- (getter)Package_get_cache_full_path,
- NULL,
- NULL,
- NULL
- },
// Dependencies
{
return (r == 0);
}
-PAKFIRE_EXPORT char* pakfire_cache_get_package_path(PakfireCache cache, PakfirePackage pkg) {
- char buffer[STRING_SIZE] = "";
-
- const char* filename = pakfire_package_get_filename(pkg);
- const char* checksum = pakfire_package_get_checksum(pkg);
-
- if (strlen(checksum) < 3)
- return NULL;
-
- snprintf(buffer, sizeof(buffer), "%c%c/%s/%s", checksum[0], checksum[1],
- checksum + 2, filename);
-
- return pakfire_strdup(buffer);
-}
-
-PAKFIRE_EXPORT int pakfire_cache_has_package(PakfireCache cache, PakfirePackage pkg) {
- char* filename = pakfire_cache_get_package_path(cache, pkg);
-
- int r = pakfire_cache_has_file(cache, filename);
- pakfire_free(filename);
-
- return r;
-}
-
PAKFIRE_EXPORT int pakfire_cache_age(PakfireCache cache, const char* filename) {
struct stat buf;
int r = pakfire_cache_stat(cache, filename, &buf);
char* pakfire_cache_get_full_path(PakfireCache cache, const char* path);
int pakfire_cache_has_file(PakfireCache cache, const char* filename);
-char* pakfire_cache_get_package_path(PakfireCache cache, PakfirePackage pkg);
-int pakfire_cache_has_package(PakfireCache cache, PakfirePackage pkg);
int pakfire_cache_age(PakfireCache cache, const char* filename);
FILE* pakfire_cache_open(PakfireCache cache, const char* filename, const char* flags);
+++ /dev/null
-/*#############################################################################
-# #
-# Pakfire - The IPFire package management system #
-# Copyright (C) 2013 Pakfire development team #
-# #
-# This program is free software: you can redistribute it and/or modify #
-# it under the terms of the GNU General Public License as published by #
-# the Free Software Foundation, either version 3 of the License, or #
-# (at your option) any later version. #
-# #
-# This program is distributed in the hope that it will be useful, #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
-# GNU General Public License for more details. #
-# #
-# You should have received a copy of the GNU General Public License #
-# along with this program. If not, see <http://www.gnu.org/licenses/>. #
-# #
-#############################################################################*/
-
-#ifndef PAKFIRE_PACKAGECACHE_H
-#define PAKFIRE_PACKAGECACHE_H
-
-#include <pakfire/types.h>
-
-PakfirePackageCache pakfire_packagecache_create(PakfirePool pool, const char* path);
-void pakfire_packagecache_free(PakfirePackageCache cache);
-
-const char* pakfire_packagecache_get_path(PakfirePackageCache cache);
-
-int pakfire_packagecache_has_package(PakfirePackageCache cache, PakfirePackage pkg);
-
-#ifdef PAKFIRE_PRIVATE
-
-struct _PakfirePackageCache {
- PakfirePool pool;
-};
-
-#endif
-
-#endif /* PAKFIRE_PACKAGECACHE_H */
pakfire_count_packages;
pakfire_create;
pakfire_get_arch;
+ pakfire_get_cache_path;
pakfire_get_installed_repo;
pakfire_get_installonly;
pakfire_get_path;
pakfire_get_pool;
pakfire_ref;
pakfire_search;
+ pakfire_set_cache_path;
pakfire_set_installed_repo;
pakfire_set_installonly;
pakfire_unref;
pakfire_package_get_buildhost;
pakfire_package_get_buildtime;
pakfire_package_get_cache_path;
- pakfire_package_get_cache_full_path;
pakfire_package_get_checksum;
pakfire_package_get_conflicts;
pakfire_package_get_description;
}
PAKFIRE_EXPORT int pakfire_package_is_cached(PakfirePackage pkg) {
- PakfirePool pool = pakfire_get_pool(pkg->pakfire);
- PakfireCache cache = pakfire_pool_get_cache(pool);
- pakfire_pool_unref(pool);
+ char* path = pakfire_package_get_cache_path(pkg);
- if (!cache)
- return 1;
+ // Check if the file is readable
+ int r = access(path, R_OK);
+ pakfire_free(path);
- return pakfire_cache_has_package(cache, pkg);
+ return r;
}
PAKFIRE_EXPORT char* pakfire_package_get_cache_path(PakfirePackage pkg) {
- PakfirePool pool = pakfire_get_pool(pkg->pakfire);
- PakfireCache cache = pakfire_pool_get_cache(pool);
- pakfire_pool_unref(pool);
-
- if (!cache)
- return NULL;
+ char buffer[STRING_SIZE] = "";
- return pakfire_cache_get_package_path(cache, pkg);
-}
+ const char* filename = pakfire_package_get_filename(pkg);
+ const char* checksum = pakfire_package_get_checksum(pkg);
-PAKFIRE_EXPORT char* pakfire_package_get_cache_full_path(PakfirePackage pkg) {
- char* cache_path = NULL;
-
- char* pkg_cache_path = pakfire_package_get_cache_path(pkg);
- if (!pkg_cache_path)
+ if (strlen(checksum) < 3)
return NULL;
- PakfireRepo repo = pakfire_package_get_repo(pkg);
- if (!repo)
- goto out;
-
- PakfireRepoCache repo_cache = pakfire_repo_get_cache(repo);
- if (!repo_cache) {
- goto out;
- }
-
- cache_path = pakfire_repocache_get_full_path(repo_cache, pkg_cache_path);
-
-out:
- pakfire_repo_unref(repo);
+ snprintf(buffer, sizeof(buffer), "%c%c/%s/%s", checksum[0], checksum[1],
+ checksum + 2, filename);
- return cache_path;
+ return pakfire_get_cache_path(pkg->pakfire, buffer);
}
PAKFIRE_EXPORT PakfireArchive pakfire_package_get_archive(PakfirePackage pkg) {
return pakfire_archive_ref(pkg->archive);
// Otherwise open the archive from the cache
- char* path = pakfire_package_get_cache_full_path(pkg);
+ char* path = pakfire_package_get_cache_path(pkg);
PakfireArchive archive = pakfire_archive_open(pkg->pakfire, path);
// Free resources
+++ /dev/null
-/*#############################################################################
-# #
-# Pakfire - The IPFire package management system #
-# Copyright (C) 2013 Pakfire development team #
-# #
-# This program is free software: you can redistribute it and/or modify #
-# it under the terms of the GNU General Public License as published by #
-# the Free Software Foundation, either version 3 of the License, or #
-# (at your option) any later version. #
-# #
-# This program is distributed in the hope that it will be useful, #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
-# GNU General Public License for more details. #
-# #
-# You should have received a copy of the GNU General Public License #
-# along with this program. If not, see <http://www.gnu.org/licenses/>. #
-# #
-#############################################################################*/
-
-#include <sys/stat.h>
-
-#include <pakfire/constants.h>
-#include <pakfire/package.h>
-#include <pakfire/packagecache.h>
-#include <pakfire/private.h>
-#include <pakfire/types.h>
-#include <pakfire/util.h>
-
-PAKFIRE_EXPORT PakfirePackageCache pakfire_packagecache_create(PakfirePool pool, const char* path) {
- PakfirePackageCache cache = pakfire_calloc(1, sizeof(*cache));
-
- cache->pool = pool;
- cache->path = pakfire_strdup(path);
-
- return cache;
-}
-
-PAKFIRE_EXPORT void pakfire_packagecache_free(PakfirePackageCache cache) {
- pakfire_free(cache->path);
- pakfire_free(cache);
-}
-
-PAKFIRE_EXPORT const char* pakfire_packagecache_get_path(PakfirePackageCache cache) {
- return cache->path;
-}
-
-PAKFIRE_EXPORT char* pakfire_packagecache_get_package_path(PakfirePackageCache cache, PakfirePackage pkg) {
- char buffer[STRING_SIZE] = "";
-
- const char* filename = pakfire_package_get_filename(pkg);
- const char* checksum = pakfire_package_get_checksum(pkg);
-
- if (strlen(checksum) < 3)
- return NULL;
-
- snprintf(buffer, sizeof(buffer), "%s/%c%c/%s/%s", cache->path,
- checksum[0], checksum[1], checksum + 2, filename);
-
- return pakfire_strdup(buffer);
-}
-
-PAKFIRE_EXPORT int pakfire_packagecache_has_package(PakfirePackageCache cache, PakfirePackage pkg) {
- char* filename = pakfire_packagecache_get_package_path(cache, pkg);
-
- // Check if stat() is successful.
- struct stat buf;
- int r = stat(filename, &buf);
-
- pakfire_free(filename);
- return (r == 0);
-}
}
PAKFIRE_EXPORT int pakfire_step_needs_download(PakfireStep step) {
- PakfirePool pool = NULL;
- int ret = true;
-
if (!pakfire_step_get_downloadtype(step))
return false;
PakfireRepo repo = pakfire_package_get_repo(step->package);
- if (pakfire_repo_is_installed_repo(repo)) {
- ret = false;
- goto finish;
- }
-
- pool = pakfire_get_pool(step->pakfire);
- PakfireCache cache = pakfire_pool_get_cache(pool);
- if (!cache)
- goto finish;
+ if (pakfire_repo_is_installed_repo(repo))
+ return false;
// Return false if package is in cache.
- ret = !pakfire_cache_has_package(cache, step->package);
-
-finish:
- pakfire_pool_unref(pool);
+ if (pakfire_package_is_cached(step->package) == 0)
+ return false;
- return ret;
+ return true;
}
static int pakfire_step_verify(PakfireStep step) {