]> pd.if.org Git - zpackage/commitdiff
treat - as stdout for zpm-extract
authorNathan Wagner <nw@hydaspes.if.org>
Fri, 3 Mar 2017 11:48:59 +0000 (05:48 -0600)
committerNathan Wagner <nw@hydaspes.if.org>
Sun, 5 Mar 2017 15:05:14 +0000 (09:05 -0600)
lib/zpm.c
t/extract.t
zpm-extract.c

index 9d62ad7d7debb32172cb4ee50299c01f7161a467..99984fbef7d645864fa235fdfdd072dd1a9a0682 100644 (file)
--- a/lib/zpm.c
+++ b/lib/zpm.c
@@ -434,12 +434,16 @@ 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);
 
@@ -449,8 +453,7 @@ int zpm_extract(struct zpm *pkg, char *hash, char *path, int mode) {
 
        sqlite3_finalize(ifile);
 
-       return 0;
-       
+       return 1;
 }
 
 /* flags 0, close mmap, flags 1, return mmap fd */
index 17b2faa2da8a8f8797386a51621d48c9e7ed18be..52a01d3f433785a75da57db8e856445f975c968f 100755 (executable)
@@ -4,7 +4,7 @@
 
 . tap.sh
 
-plan 4
+plan 5
 
 PF=test.db
 
@@ -25,6 +25,9 @@ okexit extract foo file content
 sha=$(zpm-hash test.foo2)
 okstreq $hash $sha extracted hash matches
 
+sha=$(zpm-extract $PF $hash - | zpm-hash)
+okstreq $hash $sha stdout extract hash matches
+
 finish
 
 rm -f test.*
index e050bf230a89a88904a076e4a23bba5e7f127b79..76528abf6e3861159d365140a768f179116dfce8 100644 (file)
 int main(int ac, char **av){
        struct zpm pkg;
        int mode = 0644;
+       int rv;
 
        if (ac < 3) {
                fprintf(stderr, "usage: db hash file\n");
                return 1;
        }
        zpm_open(&pkg, av[1]);
-       zpm_extract(&pkg, av[2], av[3], mode);
+       rv = zpm_extract(&pkg, av[2], av[3], mode);
        zpm_close(&pkg);
+       return rv ? 0 : 1;
 }
 #else