From 170b4a1f01f36df0ac0d6dcf6045525e1bde8a15 Mon Sep 17 00:00:00 2001 From: Enno Boland Date: Tue, 13 Aug 2024 00:00:50 +0200 Subject: [PATCH] wip --- subprojects/cextras.wrap | 2 +- tools/src/unpack.c | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/subprojects/cextras.wrap b/subprojects/cextras.wrap index 5562806c..ecf29456 100644 --- a/subprojects/cextras.wrap +++ b/subprojects/cextras.wrap @@ -1,6 +1,6 @@ [wrap-git] directory = cextras -revision = 63d5d1eae0ba7f66a34965d3c153bb0add64325d +revision = 5cc7d68fec580b292eec4d32d84084dbaed97f69 url = https://github.com/Gottox/cextras.git depth = 1 diff --git a/tools/src/unpack.c b/tools/src/unpack.c index e2c0464a..0be1e9f9 100644 --- a/tools/src/unpack.c +++ b/tools/src/unpack.c @@ -39,15 +39,15 @@ #include #include #include +#include #include #include #include -#define EXTRACT_BARRIER_INTERVAL (1024 * 1) - typedef int (*extract_fn)( const char *, enum SqshFileType, const struct SqshFile *); +size_t max_open_files = 0; size_t extracted_files = 0; bool do_chown = false; bool verbose = false; @@ -234,7 +234,7 @@ extract_file(const char *path, const struct SqshFile *file) { fd = -1; extracted_files++; - if (extracted_files % EXTRACT_BARRIER_INTERVAL == 0) { + if (extracted_files % max_open_files == 0) { rv = sqsh_threadpool_wait(threadpool); if (rv < 0) { goto out; @@ -449,6 +449,7 @@ main(int argc, char *argv[]) { struct SqshArchive *sqsh; struct SqshFile *src_root = NULL; uint64_t offset = 0; + struct rlimit limits = {0}; if (isatty(STDOUT_FILENO)) { print_segment = print_escaped; } @@ -498,7 +499,15 @@ main(int argc, char *argv[]) { goto out; } - threadpool = sqsh_threadpool_new(1, &rv); + threadpool = sqsh_threadpool_new(0, &rv); + + rv = getrlimit(RLIMIT_NOFILE, &limits); + if (rv < 0) { + perror("getrlimit"); + rv = EXIT_FAILURE; + goto out; + } + max_open_files = limits.rlim_cur / 2; src_root = sqsh_lopen(sqsh, src_path, &rv); if (rv < 0) { @@ -523,6 +532,11 @@ main(int argc, char *argv[]) { rv = EXIT_FAILURE; goto out; } + rv = sqsh_threadpool_wait(threadpool); + if (rv < 0) { + rv = EXIT_FAILURE; + goto out; + } sqsh_threadpool_free(threadpool); threadpool = NULL;