summaryrefslogtreecommitdiff
path: root/src/io.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2012-02-22 08:45:40 +0200
committerTimo Teräs <timo.teras@iki.fi>2012-02-22 08:45:40 +0200
commitbf82e2e5fd45f4ba425a128ae4fdb6144c82f218 (patch)
treeb7d97e0aede851d3d0222ee30141cb00bccf217f /src/io.c
parent568d57336d84179b3e97a301872890dc51969a36 (diff)
downloadapk-tools-bf82e2e5fd45f4ba425a128ae4fdb6144c82f218.tar.gz
apk-tools-bf82e2e5fd45f4ba425a128ae4fdb6144c82f218.tar.bz2
apk-tools-bf82e2e5fd45f4ba425a128ae4fdb6144c82f218.tar.xz
apk-tools-bf82e2e5fd45f4ba425a128ae4fdb6144c82f218.zip
db, solver, io: scan cache items at startup
It is faster to just scan the cache directory for existing packages at startup than trying to faccessat() them on demand. It also makes quite a few parts of the code more readable and simpler.
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/io.c b/src/io.c
index b9a41f4..8bb80c0 100644
--- a/src/io.c
+++ b/src/io.c
@@ -14,6 +14,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <malloc.h>
+#include <dirent.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <sys/stat.h>
@@ -542,6 +543,32 @@ int apk_file_get_info(int atfd, const char *filename, unsigned int flags,
return 0;
}
+int apk_dir_foreach_file(int dirfd, apk_dir_file_cb cb, void *ctx)
+{
+ struct dirent *de;
+ DIR *dir;
+
+ if (dirfd < 0)
+ return -1;
+
+ dir = fdopendir(dirfd);
+ if (dir == NULL)
+ return -1;
+
+ /* We get called here with dup():ed fd. Since they all refer to
+ * same object, we need to rewind so subsequent calls work. */
+ rewinddir(dir);
+
+ while ((de = readdir(dir)) != NULL) {
+ if (de->d_name[0] == '.')
+ continue;
+ cb(ctx, de->d_name);
+ }
+ closedir(dir);
+
+ return 0;
+}
+
struct apk_istream *apk_istream_from_file_gz(int atfd, const char *file)
{
return apk_bstream_gunzip(apk_bstream_from_file(atfd, file));