Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Gottox committed Aug 12, 2024
1 parent 0d929df commit 170b4a1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion subprojects/cextras.wrap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[wrap-git]
directory = cextras
revision = 63d5d1eae0ba7f66a34965d3c153bb0add64325d
revision = 5cc7d68fec580b292eec4d32d84084dbaed97f69
url = https://github.com/Gottox/cextras.git
depth = 1

Expand Down
22 changes: 18 additions & 4 deletions tools/src/unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <unistd.h>
#include <utime.h>

#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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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;

Expand Down

0 comments on commit 170b4a1

Please sign in to comment.