/* now, parse the options, return optind so the caller can adjust if needed */
- return 1;
+ return av ? ac : 1;
}
int zpm_extract(struct zpm *pkg, char *hash, char *path, int mode) {
xzdata = (void *)sqlite3_column_blob(ifile, 1);
blobsize = sqlite3_column_bytes(ifile, 1);
- out = fopen(path, "w");
+ if (strcmp(path, "-")) {
+ out = fopen(path, "w");
+ } else {
+ out = stdout;
+ }
if (!out) {
fprintf(stderr, "can't open output file %s\n", path);
sqlite3_finalize(ifile);
sqlite3_close(db);
- return 5;
+ return 0;
}
//fwrite(xzdata, blobsize, 1, stdout);
//fprintf(stderr, "uncompressing %d bytes at %p, expect %lld\n", blobsize, xzdata, (long long int)size);
uncompresslzma(xzdata, blobsize, out);
fclose(out);
+ chmod(path, mode);
sqlite3_finalize(ifile);
- return 0;
-
+ return 1;
}
/* flags 0, close mmap, flags 1, return mmap fd */
}
hash[64] = 0;
munmap(content, sbuf.st_size);
- return 1;
+ return flags ? fd : 1;
}
static sqlite3_stmt *run_for_hash(sqlite3 *db, char *sql, char *hash) {
hash = hashbuf;
}
+ flags = 0; /* suppress warning, probably use to follow symlinks */
/* mmap the file */
fd = open(path, O_RDONLY);
if (fd == -1) {