void dcmd(char *arname, int count, char **files) { Armember *bp; int fd, i; if (!count) return; fd = openar(arname, ORDWR, 0); Binit(&bar, fd, OREAD); Bseek(&bar,seek(fd,0,1), 1); astart = newtempfile(artemp); for (i = 0; bp = getdir(&bar); i++) { if(match(count, files)) { mesg('d', file); skip(&bar, bp->size); if (strcmp(file, symdef) == 0) allobj = 0; } else if (i == 0 && strcmp(file, symdef) == 0) skip(&bar, bp->size); else { scanobj(&bar, astart, bp->size); arcopy(&bar, astart, bp); } } close(fd); install(arname, astart, 0, 0, 0); }
void mcmd(char *arname, int count, char **files) { int fd, i; Arfile *ap; Armember *bp; if (count == 0) return; fd = openar(arname, ORDWR, 0); Binit(&bar, fd, OREAD); Bseek(&bar,seek(fd,0,1), 1); astart = newtempfile(artemp); amiddle = newtempfile(movtemp); aend = 0; ap = astart; for (i = 0; bp = getdir(&bar); i++) { if (bamatch(file, poname)) { aend = newtempfile(tailtemp); ap = aend; } if(match(count, files)) { mesg('m', file); scanobj(&bar, amiddle, bp->size); arcopy(&bar, amiddle, bp); } else /* * pitch the symdef file if it is at the beginning * of the archive and we aren't inserting in front * of it (ap == astart). */ if (ap == astart && i == 0 && strcmp(file, symdef) == 0) skip(&bar, bp->size); else { scanobj(&bar, ap, bp->size); arcopy(&bar, ap, bp); } } close(fd); if (poname[0] && aend == 0) fprint(2, "ar: %s not found - files moved to end.\n", poname); install(arname, astart, amiddle, aend, 0); }
void xcmd(char *arname, int count, char **files) { int fd, f, mode, i; Armember *bp; Dir dx; fd = openar(arname, OREAD, 0); Binit(&bar, fd, OREAD); Bseek(&bar,seek(fd,0,1), 1); i = 0; while (bp = getdir(&bar)) { if(count == 0 || match(count, files)) { mode = strtoul(bp->hdr.mode, 0, 8) & 0777; f = create(file, OWRITE, mode); if(f < 0) { fprint(2, "ar: %s cannot create\n", file); skip(&bar, bp->size); } else { mesg('x', file); arcopy(&bar, 0, bp); if (write(f, bp->member, bp->size) < 0) wrerr(); if(oflag) { nulldir(&dx); dx.atime = bp->date; dx.mtime = bp->date; if(dirwstat(file, &dx) < 0) perror(file); } free(bp->member); close(f); } free(bp); if (count && ++i >= count) break; } else { skip(&bar, bp->size); free(bp); } } close(fd); }
void qcmd(char *arname, int count, char **files) { int fd, i; Armember *bp; Biobuf *bfile; if(aflag || bflag) { fprint(2, "ar: abi not allowed with q\n"); exits("error"); } fd = openar(arname, ORDWR, 1); if (fd < 0) { if(!cflag) fprint(2, "ar: creating %s\n", arname); fd = arcreate(arname); } Binit(&bar, fd, OREAD); Bseek(&bar,seek(fd,0,1), 1); /* leave note group behind when writing archive; i.e. sidestep interrupts */ rfork(RFNOTEG); Bseek(&bar, 0, 2); bp = newmember(); for(i=0; i<count && files[i]; i++) { file = files[i]; files[i] = 0; bfile = Bopen(file, OREAD); if(!bfile) fprint(2, "ar: %s cannot open\n", file); else { mesg('q', file); armove(bfile, 0, bp); if (!arwrite(fd, bp)) wrerr(); free(bp->member); bp->member = 0; Bterm(bfile); } } free(bp); close(fd); }
void tcmd(char *arname, int count, char **files) { int fd; Armember *bp; char name[ARNAMESIZE+1]; fd = openar(arname, OREAD, 0); Binit(&bar, fd, OREAD); Bseek(&bar,seek(fd,0,1), 1); while(bp = getdir(&bar)) { if(count == 0 || match(count, files)) { if(vflag) longt(bp); trim(file, name, ARNAMESIZE); Bprint(&bout, "%s\n", name); } skip(&bar, bp->size); free(bp); } close(fd); }
void pcmd(char *arname, int count, char **files) { int fd; Armember *bp; fd = openar(arname, OREAD, 0); Binit(&bar, fd, OREAD); Bseek(&bar,seek(fd,0,1), 1); while(bp = getdir(&bar)) { if(count == 0 || match(count, files)) { if(vflag) print("\n<%s>\n\n", file); arcopy(&bar, 0, bp); if (write(1, bp->member, bp->size) < 0) wrerr(); } else skip(&bar, bp->size); free(bp); } close(fd); }
/* * perform the 'r' and 'u' commands */ void arcmd(char *arname, int count, char **files) { int fd; int i; Arfile *ap; Armember *bp; Dir *d; Biobuf *bfile; fd = openar(arname, ORDWR, 1); if (fd >= 0) { Binit(&bar, fd, OREAD); Bseek(&bar,seek(fd,0,1), 1); } astart = newtempfile(artemp); ap = astart; aend = 0; for(i = 0; fd >= 0; i++) { bp = getdir(&bar); if (!bp) break; if (bamatch(file, poname)) { /* check for pivot */ aend = newtempfile(tailtemp); ap = aend; } /* pitch symdef file */ if (i == 0 && strcmp(file, symdef) == 0) { skip(&bar, bp->size); continue; } if (count && !match(count, files)) { scanobj(&bar, ap, bp->size); arcopy(&bar, ap, bp); continue; } bfile = Bopen(file, OREAD); if (!bfile) { if (count != 0) fprint(2, "ar: cannot open %s\n", file); scanobj(&bar, ap, bp->size); arcopy(&bar, ap, bp); continue; } d = dirfstat(Bfildes(bfile)); if (d == nil) fprint(2, "ar: cannot stat %s: %r\n", file); if (uflag && (d == nil || d->mtime <= bp->date)) { scanobj(&bar, ap, bp->size); arcopy(&bar, ap, bp); Bterm(bfile); free(d); continue; } mesg('r', file); skip(&bar, bp->size); scanobj(bfile, ap, d->length); free(d); armove(bfile, ap, bp); Bterm(bfile); } if(fd >= 0) close(fd); /* copy in remaining files named on command line */ for (i = 0; i < count; i++) { file = files[i]; if(file == 0) continue; files[i] = 0; bfile = Bopen(file, OREAD); if (!bfile) fprint(2, "ar: %s cannot open\n", file); else { mesg('a', file); d = dirfstat(Bfildes(bfile)); if (d == nil) fprint(2, "ar: can't stat %s: %r\n", file); else { scanobj(bfile, astart, d->length); armove(bfile, astart, newmember()); free(d); } Bterm(bfile); } } if(fd < 0 && !cflag) install(arname, astart, 0, aend, 1); /* issue 'creating' msg */ else install(arname, astart, 0, aend, 0); }