]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: Add function to check if file exists/is readable/is writable in cache
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 Jan 2018 13:03:27 +0000 (14:03 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 Jan 2018 13:03:27 +0000 (14:03 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/cache.c
src/libpakfire/include/pakfire/cache.h
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/pakfire.c
src/libpakfire/repocache.c

index ab2ed3fecda589af6182a2832e519ed4abcc55fe..3ae7791998af3884539979913a792949dadcae39 100644 (file)
@@ -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);
-}
index 3385b7f83b54f8ac07f044d7b577566988898f09..b616da997ca073fdcd58703dbbc93fa7c742f8b5 100644 (file)
@@ -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 {
index 88769f7d5a3ffb26453dbe729ac085b804090477..661c83934980bcf0b3327216f58df14955601bb0 100644 (file)
@@ -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);
index dcdc9006dd50cd82970ecde70f444c8da16934de..00948d8eb39dbbd5e2074787e79d014bf5d9d240 100644 (file)
@@ -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;
 
index ca3ce006cd4a2dd6bfd03fe0ad5f73e16137ac72..9bc1b8c30b10d7c81182bc950cf7375bac0f2cc4 100644 (file)
@@ -22,6 +22,7 @@
 #include <ftw.h>
 #include <stdio.h>
 #include <sys/stat.h>
+#include <unistd.h>
 
 #include <pakfire/cache.h>
 #include <pakfire/constants.h>
@@ -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;