From: Michael Tremer Date: Fri, 19 Jan 2018 13:03:27 +0000 (+0100) Subject: libpakfire: Add function to check if file exists/is readable/is writable in cache X-Git-Tag: 0.9.28~1285^2~1161 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a239b25d9d9bd332f03a3beb238c813151afcfec;p=pakfire.git libpakfire: Add function to check if file exists/is readable/is writable in cache Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/cache.c b/src/libpakfire/cache.c index ab2ed3fec..3ae779199 100644 --- a/src/libpakfire/cache.c +++ b/src/libpakfire/cache.c @@ -54,20 +54,3 @@ PAKFIRE_EXPORT char* pakfire_cache_get_full_path(PakfireCache cache, const char* return pakfire_path_join(cache_path, path); } - -static int pakfire_cache_stat(PakfireCache cache, const char* filename, struct stat* buf) { - char* cache_filename = pakfire_cache_get_full_path(cache, filename); - - int r = stat(cache_filename, buf); - pakfire_free(cache_filename); - - return r; -} - -PAKFIRE_EXPORT int pakfire_cache_has_file(PakfireCache cache, const char* filename) { - struct stat buf; - int r = pakfire_cache_stat(cache, filename, &buf); - - // Just check if stat() was sucessful. - return (r == 0); -} diff --git a/src/libpakfire/include/pakfire/cache.h b/src/libpakfire/include/pakfire/cache.h index 3385b7f83..b616da997 100644 --- a/src/libpakfire/include/pakfire/cache.h +++ b/src/libpakfire/include/pakfire/cache.h @@ -31,8 +31,6 @@ void pakfire_cache_free(PakfireCache cache); const char* pakfire_cache_get_path(PakfireCache cache); char* pakfire_cache_get_full_path(PakfireCache cache, const char* path); -int pakfire_cache_has_file(PakfireCache cache, const char* filename); - #ifdef PAKFIRE_PRIVATE struct _PakfireCache { diff --git a/src/libpakfire/include/pakfire/pakfire.h b/src/libpakfire/include/pakfire/pakfire.h index 88769f7d5..661c83934 100644 --- a/src/libpakfire/include/pakfire/pakfire.h +++ b/src/libpakfire/include/pakfire/pakfire.h @@ -59,6 +59,7 @@ char* pakfire_get_cache_path(Pakfire pakfire, const char* path); void pakfire_set_cache_path(Pakfire pakfire, const char* path); int pakfire_cache_destroy(Pakfire pakfire, const char* path); +int pakfire_cache_access(Pakfire pakfire, const char* path, int mode); int pakfire_cache_stat(Pakfire pakfire, const char* path, struct stat* buffer); time_t pakfire_cache_age(Pakfire pakfire, const char* path); FILE* pakfire_cache_open(Pakfire pakfire, const char* path, const char* flags); diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index dcdc9006d..00948d8eb 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -361,6 +361,15 @@ PAKFIRE_EXPORT int pakfire_cache_stat(Pakfire pakfire, const char* path, struct return r; } +PAKFIRE_EXPORT int pakfire_cache_access(Pakfire pakfire, const char* path, int mode) { + char* cache_path = pakfire_get_cache_path(pakfire, path); + + int r = pakfire_access(cache_path, NULL, mode); + pakfire_free(cache_path); + + return r; +} + PAKFIRE_EXPORT time_t pakfire_cache_age(Pakfire pakfire, const char* path) { struct stat buffer; diff --git a/src/libpakfire/repocache.c b/src/libpakfire/repocache.c index ca3ce006c..9bc1b8c30 100644 --- a/src/libpakfire/repocache.c +++ b/src/libpakfire/repocache.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -74,7 +75,7 @@ PAKFIRE_EXPORT int pakfire_repocache_has_file(PakfireRepoCache repo_cache, const char* cache_filename = pakfire_repocache_get_cache_path(repo_cache, filename); PakfireCache cache = pakfire_repocache_cache(repo_cache); - int r = pakfire_cache_has_file(cache, cache_filename); + int r = pakfire_cache_access(cache, cache_filename, R_OK); pakfire_free(cache_filename); return r;