1 #define _POSIX_C_SOURCE 2
16 * -t : use a temp file, then move into place, possible reverse the sense
19 * -m : mode (i.e. final mode)
21 * -l : log all actions
22 * -d : logging database file, if different
24 * check if file exists, if it does, and has the same hash, do
25 * nothing, unless -f is given
29 fprintf(stderr, "usage: zpm-extract [-d dbfile] [-t tmpfile] hash [output]\n");
32 int main(int ac, char **av){
36 char *tmpfile = 0, *output = 0;
41 char *dest = 0, *hashmatch = 0;
42 char hash[ZPM_HASH_STRLEN+1];
43 char *dbfile = getenv("ZPMDB");
45 dbfile = "/var/lib/zpm/local.db";
48 while ((opt = getopt(ac, av, "f:")) != -1) {
50 case 'f': dbfile = optarg; break;
51 case 't': tmpfile = optarg; break;
52 case 'u': uid = atoi(optarg); break;
53 case 'g': gid = atoi(optarg); break;
54 case 'o': dest = optarg; break;
55 case 'm': mode = atoi(optarg); break;
68 hashmatch = av[optind];
71 output = av[optind+1];
74 zpm_open(&pkg, dbfile);
76 rv = zpm_findhash(&pkg, hashmatch, hash);
78 fprintf(stderr, "no such hash %s\n", hashmatch);
81 fprintf(stderr, "%d matching hashes for %s\n", rv, hashmatch);
85 rv = zpm_extract(&pkg, hash, tmpfile ? tmpfile : output, 0600);
92 /* set mode and such */
94 if (dest != tmpfile) {
95 rename(tmpfile, dest);