123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #include <err.h>
- #include <stdio.h>
- #include <string.h>
- #include "zip.h"
- #include "../util.h"
- #include "../archive.h"
- static uint8_t
- Zip_match(void __unused *self, char *const file)
- {
- return match_ext(file, EXT(zip)) || match_ext(file, EXT(jar));
- }
- impl(Match, Zip);
- static int
- Zip_list(void *self, char *const file)
- {
- SELF_CFG(self, cfg);
- char *const argv[] = { "unzip", "-Z", cfg->verbose ? "-m" : "-1",
- "--", file, NULL };
- return dryrun_or_exec(cfg->dry_run, argv);
- }
- impl(List, Zip);
- static int
- Zip_extract(void *self, char *const file)
- {
- SELF_CFG(self, cfg);
- char *argv[] = { "unzip", !cfg->verbose ? "-q" : NULL,
- "-d", cfg->out_dir,
- "--", file,
- NULL };
- fiter_null(WITH_LEN(argv));
- return dryrun_or_exec(cfg->dry_run, argv);
- }
- impl(Extract, Zip);
- static int
- Zip_create(void *self, char *const archive)
- {
- SELF_CFG(self, cfg);
- char *argv[3 + cfg->files_count + 1];
- char **ptr = (char **)argv;
- *(ptr++) = "zip";
- *(ptr++) = cfg->verbose ? "-r" : "-rq";
- *(ptr++) = archive;
- for (int i = 0; i < cfg->files_count; i++)
- *(ptr++) = cfg->files[i];
- *ptr = NULL;
- return dryrun_or_exec(cfg->dry_run, argv);
- }
- impl(Create, Zip);
- implExtern(Archive, Zip);
|