pkg: fix issue #79

This commit is contained in:
cinap_lenrek 2011-08-18 01:09:52 +02:00
parent 925ac75c2c
commit 0aff2284b6
2 changed files with 31 additions and 29 deletions

View file

@ -1,4 +1,4 @@
#!/bin/rc -e #!/bin/rc
if(~ $#pkgpath 0) if(~ $#pkgpath 0)
pkgpath=http://pkg.violetti.org/$cputype pkgpath=http://pkg.violetti.org/$cputype
@ -14,6 +14,6 @@ if(~ $pkgpath ftp* http*)
cmd=hget cmd=hget
if not if not
cmd=cat cmd=cat
$cmd $pkgpath/$1.tbz | bunzip2 | pkg/unpkg>[2]/sys/lib/pkg/$1 if(! $cmd $pkgpath/$1.tbz | bunzip2 | pkg/unpkg >/sys/lib/pkg/$1)
echo Done if(! test -s /sys/lib/pkg/$1)
rm -f /sys/lib/pkg/$1

View file

@ -23,23 +23,24 @@ static char *sndup(char* s, ulong n) {
} }
int readheader(int fd, struct th* th) { int readheader(struct th* th) {
int i; int i;
char b[512]; char b[512];
if(readn(fd, b, 512) != 512) return -1;
if(readn(0, b, 512) != 512) return -1;
// Check for end of archive // Check for end of archive
for(i=0; i<512; i++) { for(i=0; i<512; i++) {
if(b[i]!=0) goto rhok; 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++) { for(i=0; i<512; i++) {
if(b[i]!=0) return -1; if(b[i]!=0) return -1;
} }
return 0; return 0;
rhok: rhok:
th->name = sndup(b, 100); th->name = cleanname(sndup(b, 100));
th->perm = strtoul(b+100, nil, 8); th->perm = strtoul(b+100, nil, 8);
th->size = strtoul(b+124, nil, 8); th->size = strtoul(b+124, nil, 8);
th->type = b[156]; th->type = b[156];
@ -48,49 +49,50 @@ int readheader(int fd, struct th* th) {
return 1; return 1;
} }
int main(void) { void main(int argc, char *argv[]) {
while(1) { ARGBEGIN {
} ARGEND;
for(;;) {
struct th th; struct th th;
ulong off; ulong off;
uchar b[512]; uchar b[512];
DigestState *s; DigestState *s;
int wfd; int r, wfd;
int r = readheader(0, &th);
if(r <= 0) return r;
r = readheader(&th);
if(r == 0)
exits(nil);
if(r < 0)
sysfatal("unexpected eof");
switch(th.type) { switch(th.type) {
case '5': case '5':
create(th.name, OREAD, DMDIR|th.perm); if((wfd = create(th.name, OREAD, DMDIR|th.perm)) >= 0)
close(wfd);
break; break;
case '0': case 0: case '0': case 0:
print("A %s\n", th.name); fprint(2, "A %s\n", th.name);
r = access(th.name, 0); if((wfd = create(th.name, OWRITE|OEXCL, th.perm)) < 0)
if(r == 0) { sysfatal("%r", th.name);
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;
}
s = nil; s = nil;
for(off=0; off<th.size; off+=512) { for(off=0; off<th.size; off+=512) {
int n = th.size-off; int n = th.size-off;
n = n<512 ? n : 512; n = n<512 ? n : 512;
if(readn(0, b, 512) != 512) return -1; if(readn(0, b, 512) != 512)
if(write(wfd, b, n) != n) return -1; sysfatal("%r");
if(write(wfd, b, n) != n)
sysfatal("%s: %r", th.name);
s = sha1(b, n, nil, s); s = sha1(b, n, nil, s);
} }
uchar digest[20], hdigest[41]; uchar digest[20], hdigest[41];
sha1(nil, 0, digest, s); sha1(nil, 0, digest, s);
enc16((char*)hdigest, 41, digest, 20); 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); close(wfd);
break; break;
default: default:
print("Unknown file type '%c'\n", th.type); sysfatal("Unknown file type '%c'", th.type);
return -1;
} }
free(th.name); free(th.name);