ref: 97db7ab3660e6f322e33682e5424bd97f21cbd6b
parent: 15b6a64ffc334be0d1810c4799a0f89526bc13da
author: cinap_lenrek <cinap_lenrek@centraldogma>
date: Wed Aug 17 21:09:52 EDT 2011
pkg: fix issue #79
--- a/sys/src/cmd/pkg/install
+++ b/sys/src/cmd/pkg/install
@@ -1,4 +1,4 @@
-#!/bin/rc -e
+#!/bin/rc
if(~ $#pkgpath 0)
pkgpath=http://pkg.violetti.org/$cputype
@@ -14,6 +14,6 @@
cmd=hget
if not
cmd=cat
-$cmd $pkgpath/$1.tbz | bunzip2 | pkg/unpkg>[2]/sys/lib/pkg/$1
-echo Done
-
+if(! $cmd $pkgpath/$1.tbz | bunzip2 | pkg/unpkg >/sys/lib/pkg/$1)
+ if(! test -s /sys/lib/pkg/$1)
+ rm -f /sys/lib/pkg/$1
--- a/sys/src/cmd/pkg/unpkg.c
+++ b/sys/src/cmd/pkg/unpkg.c
@@ -23,16 +23,17 @@
}
-int readheader(int fd, struct th* th) {+int readheader(struct th* th) {int i;
char b[512];
- if(readn(fd, b, 512) != 512) return -1;
+
+ if(readn(0, b, 512) != 512) return -1;
// Check for end of archive
for(i=0; i<512; i++) {if(b[i]!=0) goto rhok;
}
- if(readn(fd, b, 512) != 512) return -1;
+ if(readn(0, b, 512) != 512) return -1;
for(i=0; i<512; i++) {if(b[i]!=0) return -1;
}
@@ -39,7 +40,7 @@
return 0;
rhok:
- th->name = sndup(b, 100);
+ th->name = cleanname(sndup(b, 100));
th->perm = strtoul(b+100, nil, 8);
th->size = strtoul(b+124, nil, 8);
th->type = b[156];
@@ -48,37 +49,39 @@
return 1;
}
-int main(void) {- while(1) {+void main(int argc, char *argv[]) {+ ARGBEGIN {+ } ARGEND;
+ for(;;) {struct th th;
ulong off;
uchar b[512];
DigestState *s;
- int wfd;
- int r = readheader(0, &th);
- if(r <= 0) return r;
+ int r, wfd;
+ r = readheader(&th);
+ if(r == 0)
+ exits(nil);
+ if(r < 0)
+ sysfatal("unexpected eof");+
switch(th.type) {case '5':
- create(th.name, OREAD, DMDIR|th.perm);
+ if((wfd = create(th.name, OREAD, DMDIR|th.perm)) >= 0)
+ close(wfd);
break;
case '0': case 0:
- print("A %s\n", th.name);- r = access(th.name, 0);
- if(r == 0) {- print("File already exists: %s\n", th.name);- return -1;
- }
- if((wfd = create(th.name, OWRITE, th.perm)) < 0) {- print("Create failed: %s\n", th.name);- return -1;
- }
+ fprint(2, "A %s\n", th.name);
+ if((wfd = create(th.name, OWRITE|OEXCL, th.perm)) < 0)
+ sysfatal("%r", th.name);s = nil;
for(off=0; off<th.size; off+=512) {int n = th.size-off;
n = n<512 ? n : 512;
- if(readn(0, b, 512) != 512) return -1;
- if(write(wfd, b, n) != n) return -1;
+ if(readn(0, b, 512) != 512)
+ sysfatal("%r");+ if(write(wfd, b, n) != n)
+ sysfatal("%s: %r", th.name);s = sha1(b, n, nil, s);
}
@@ -85,12 +88,11 @@
uchar digest[20], hdigest[41];
sha1(nil, 0, digest, s);
enc16((char*)hdigest, 41, digest, 20);
- fprint(2, "%s\t%s\n", th.name, hdigest);
+ print("%s\t%s\n", th.name, hdigest);close(wfd);
break;
default:
- print("Unknown file type '%c'\n", th.type);- return -1;
+ sysfatal("Unknown file type '%c'", th.type);}
free(th.name);
--
⑨