Lines Matching refs:TT

141   xwrite(TT.fd, &tmp, 512);
142 xwrite(TT.fd, name, sz);
143 if (sz%512) xwrite(TT.fd, toybuf, 512-(sz%512));
160 if (lskip(TT.fd, len)) perror_exit("EOF");
163 // allocate and read data from TT.fd
171 xreadall(TT.fd, *b, len);
186 if (TT.adev == st->st_dev && TT.aino == st->st_ino) {
196 if (filter(TT.excl, lnk)) goto done;
215 if (TT.warn && hname != name) {
218 TT.warn = 0;
221 if (TT.owner) st->st_uid = TT.ouid;
222 if (TT.group) st->st_gid = TT.ggid;
223 if (TT.mode) st->st_mode = string_to_mode(TT.mode, st->st_mode);
224 if (TT.mtime) st->st_mtime = TT.mtt;
240 for (i = 0; i<TT.hlc; i++) {
241 if (st->st_ino == TT.hlx[i].ino && st->st_dev == TT.hlx[i].dev)
244 if (i != TT.hlc) {
245 lnk = TT.hlx[i].arg;
249 if (!(TT.hlc&255)) TT.hlx = xrealloc(TT.hlx, TT.hlc+256);
250 TT.hlx[TT.hlc].arg = xstrdup(hname);
251 TT.hlx[TT.hlc].ino = st->st_ino;
252 TT.hlx[TT.hlc].dev = st->st_dev;
253 TT.hlc++;
291 if (TT.owner || (pw = bufgetpwuid(st->st_uid)))
292 strncpy(hdr.uname, TT.owner ? TT.owner : pw->pw_name, sizeof(hdr.uname));
293 if (TT.group || (gr = bufgetgrgid(st->st_gid)))
294 strncpy(hdr.gname, TT.group ? TT.group : gr->gr_name, sizeof(hdr.gname));
297 TT.sparselen = 0;
310 if (!(TT.sparselen&511))
311 TT.sparse = xrealloc(TT.sparse, (TT.sparselen+514)*sizeof(long long));
313 TT.sparse[TT.sparselen++] = ld;
314 len += TT.sparse[TT.sparselen++] = lo-ld;
320 if (TT.sparselen>2) {
321 TT.sparse[TT.sparselen++] = st->st_size;
322 TT.sparse[TT.sparselen++] = 0;
325 for (i = 0; i<TT.sparselen && i<8; i++)
326 itoo(lnk+386+12*i, 12, TT.sparse[i]);
330 if (TT.sparselen>8) lnk[482] = 1;
333 } else TT.sparselen = 0;
341 if (FLAG(v)) dprintf(TT.fd ? 2 : 1, "%s\n", hname);
344 xwrite(TT.fd, &hdr, 512);
345 if (TT.sparselen>8) {
352 if (!j || i==TT.sparselen) {
354 if (i!=TT.sparselen) buf[504] = 1;
355 xwrite(TT.fd, buf, 512);
357 if (i==TT.sparselen) break;
360 itoo(buf+12*j, 12, TT.sparse[i]);
363 TT.sparselen >>= 1;
365 if (hdr.type == '0') xsendfile_pad(fd, TT.fd, st->st_size);
366 else for (i = 0; i<TT.sparselen; i++) {
367 if (TT.sparse[i*2] != lseek(fd, TT.sparse[i*2], SEEK_SET))
368 perror_msg("%s: seek %lld", name, TT.sparse[i*2]);
369 xsendfile_pad(fd, TT.fd, TT.sparse[i*2+1]);
371 if (st->st_size%512) writeall(TT.fd, toybuf, (512-(st->st_size%512)));
393 // Barf if name not in TT.cwd
396 if (TT.cwd[1] && (!strstart(&ss, TT.cwd) || *ss!='/')) {
397 error_msg("'%s' not under '%s'", name, TT.cwd);
404 free(TT.cwd);
405 TT.cwd = strdup(s);
412 while (TT.dirs) {
417 wsettime(TT.dirs->str+sizeof(long long), *(long long *)TT.dirs->str);
418 free(llist_pop(&TT.dirs));
422 // name was under TT.cwd
433 if (TT.sparselen) {
435 if (-1 == lseek(fd, len = TT.sparse[i*2], SEEK_SET)) {
445 if (!(len = TT.sparse[i*2+1]) && ftruncate(fd, sent+len))
448 if (len+used>TT.hdr.size) error_exit("sparse overflow");
449 } else len = TT.hdr.size;
451 len -= sendfile_len(TT.fd, fd, len, &sent);
456 skippy(TT.hdr.size-used);
460 } while (++i<TT.sparselen);
467 char *name = TT.hdr.name;
468 int ala = TT.hdr.mode;
471 if (S_ISREG(ala) && !TT.hdr.link_target) skippy(TT.hdr.size);
486 if (TT.hdr.link_target) {
487 if (link(TT.hdr.link_target, name))
488 return perror_msg("can't link '%s' -> '%s'", name, TT.hdr.link_target);
494 else skippy(TT.hdr.size);
498 return perror_msg("%s: can't create", TT.hdr.name);
500 if (symlink(TT.hdr.link_target, TT.hdr.name))
501 return perror_msg("can't link '%s' -> '%s'", name, TT.hdr.link_target);
502 } else if (mknod(name, ala, TT.hdr.device))
507 int u = TT.hdr.uid, g = TT.hdr.gid;
509 if (TT.owner) TT.hdr.uid = TT.ouid;
510 else if (!FLAG(numeric_owner) && *TT.hdr.uname) {
511 struct passwd *pw = getpwnam(TT.hdr.uname);
512 if (pw && (TT.owner || !FLAG(numeric_owner))) TT.hdr.uid = pw->pw_uid;
515 if (TT.group) TT.hdr.gid = TT.ggid;
516 else if (!FLAG(numeric_owner) && *TT.hdr.uname) {
517 struct group *gr = getgrnam(TT.hdr.gname);
518 if (gr) TT.hdr.gid = gr->gr_gid;
524 if (!S_ISLNK(ala)) chmod(TT.hdr.name, FLAG(p) ? ala : ala&0777);
535 *(long long *)sl->str = TT.hdr.mtime;
537 sl->next = TT.dirs;
538 TT.dirs = sl;
539 } else wsettime(TT.hdr.name, TT.hdr.mtime);
557 if (TT.hdr.size%512) skippy(512-TT.hdr.size%512);
558 i = readall(TT.fd, &tar, 512);
566 TT.hdr.size = 0;
574 TT.hdr.size = OTOI(tar.size);
581 if (tar.type == 'K') alloread(&TT.hdr.link_target, TT.hdr.size);
582 else if (tar.type == 'L') alloread(&TT.hdr.name, TT.hdr.size);
588 alloread(&buf, TT.hdr.size);
589 for (p = buf; (p-buf)<TT.hdr.size; p += len) {
591 if (i<1 || len<4 || len>TT.hdr.size) {
597 TT.hdr.name = xstrdup(p+n);
604 } else skippy(TT.hdr.size);
616 TT.sparselen = 0;
621 if (!(TT.sparselen&511))
622 TT.sparse = xrealloc(TT.sparse, (TT.sparselen+512)*sizeof(long long));
627 xreadall(TT.fd, s = sparse, 512);
632 TT.sparse[TT.sparselen++] = otoi(s, 12);
637 TT.sparselen /= 2;
638 if (TT.sparselen)
639 TT.hdr.ssize = TT.sparse[2*TT.sparselen-1]+TT.sparse[2*TT.sparselen-2];
641 TT.sparselen = 0;
642 TT.hdr.ssize = TT.hdr.size;
646 TT.hdr.mode = OTOI(tar.mode)&0xfff;
647 if (tar.type == 'S' || !tar.type) TT.hdr.mode |= 0x8000;
648 else TT.hdr.mode |= (char []){8,8,10,2,6,4,1,8}[tar.type-'0']<<12;
649 TT.hdr.uid = OTOI(tar.uid);
650 TT.hdr.gid = OTOI(tar.gid);
651 TT.hdr.mtime = OTOI(tar.mtime);
654 TT.hdr.device = dev_makedev(maj, min);
655 TT.hdr.uname = xstrndup(TT.owner ? TT.owner : tar.uname, sizeof(tar.uname));
656 TT.hdr.gname = xstrndup(TT.group ? TT.group : tar.gname, sizeof(tar.gname));
658 if (TT.owner) TT.hdr.uid = TT.ouid;
660 struct passwd *pw = getpwnam(TT.hdr.uname);
661 if (pw && (TT.owner || !FLAG(numeric_owner))) TT.hdr.uid = pw->pw_uid;
664 if (TT.group) TT.hdr.gid = TT.ggid;
666 struct group *gr = getgrnam(TT.hdr.gname);
667 if (gr) TT.hdr.gid = gr->gr_gid;
670 if (!TT.hdr.link_target && *tar.link)
671 TT.hdr.link_target = xstrndup(tar.link, sizeof(tar.link));
672 if (!TT.hdr.name) {
675 TT.hdr.name = xmprintf("%.*s%s%.*s", i, tar.prefix,
681 if (S_ISREG(TT.hdr.mode) && (s = strend(TT.hdr.name, "/"))) {
683 TT.hdr.mode = (TT.hdr.mode & ~S_IFMT) | S_IFDIR;
687 if ((TT.hdr.link_target && *TT.hdr.link_target)
688 || (tar.type && !S_ISREG(TT.hdr.mode)))
689 TT.hdr.size = 0;
692 // TT.seen points to first seen entry in TT.incl, or NULL if none yet.
694 if ((delete = filter(TT.incl, TT.hdr.name)) && TT.incl != TT.seen) {
695 if (!TT.seen) TT.seen = delete;
698 if (TT.incl == delete) TT.incl = TT.incl->next;
699 else for (walk = TT.incl; walk != TT.seen; walk = walk->next) {
702 dlist_add_nomalloc(&TT.incl, delete);
708 if (filter(TT.excl, TT.hdr.name) || (TT.incl && !delete))
709 skippy(TT.hdr.size);
712 struct tm *lc = localtime(TT.mtime ? &TT.mtt : &TT.hdr.mtime);
715 mode_to_string(TT.hdr.mode, perm);
717 sprintf(perm, "%u", TT.hdr.uid);
718 sprintf(gname, "%u", TT.hdr.gid);
719 printf(" %s/%s ", *TT.hdr.uname ? TT.hdr.uname : perm,
720 *TT.hdr.gname ? TT.hdr.gname : gname);
722 else printf("%9lld", TT.hdr.ssize);
727 printf("%s", TT.hdr.name);
728 if (TT.hdr.link_target) printf(" -> %s", TT.hdr.link_target);
730 skippy(TT.hdr.size);
732 if (FLAG(v)) printf("%s\n", TT.hdr.name);
735 if (S_ISREG(TT.hdr.mode)) {
739 xsetenv(xmprintf("TAR_MODE=%o", TT.hdr.mode), 0);
740 xsetenv(xmprintf("TAR_SIZE=%lld", TT.hdr.ssize), 0);
741 xsetenv("TAR_FILENAME", TT.hdr.name);
742 xsetenv("TAR_UNAME", TT.hdr.uname);
743 xsetenv("TAR_GNAME", TT.hdr.gname);
744 xsetenv(xmprintf("TAR_MTIME=%llo", (long long)TT.hdr.mtime), 0);
745 xsetenv(xmprintf("TAR_UID=%o", TT.hdr.uid), 0);
746 xsetenv(xmprintf("TAR_GID=%o", TT.hdr.gid), 0);
748 pid = xpopen((char *[]){"sh", "-c", TT.to_command, NULL}, &fd, 0);
757 free(TT.hdr.name);
758 free(TT.hdr.link_target);
759 free(TT.hdr.uname);
760 free(TT.hdr.gname);
761 TT.hdr.name = TT.hdr.link_target = 0;
777 // do_lines callback, selects TT.incl or TT.excl based on call order
780 if (pline) trim2list(TT.X ? &TT.excl : &TT.incl, *pline);
794 if (TT.owner) TT.ouid = xgetuid(TT.owner);
795 if (TT.group) TT.ggid = xgetgid(TT.group);
796 if (TT.mtime) xparsedate(TT.mtime, &TT.mtt, (void *)&s, 1);
799 for (; TT.exclude; TT.exclude = TT.exclude->next)
800 trim2list(&TT.excl, TT.exclude->arg);
801 for (;TT.X; TT.X = TT.X->next) do_lines(xopenro(TT.X->arg), '\n', do_XT);
802 for (args = toys.optargs; *args; args++) trim2list(&TT.incl, *args);
803 for (;TT.T; TT.T = TT.T->next) do_lines(xopenro(TT.T->arg), '\n', do_XT);
807 if (!TT.incl) error_exit("empty archive");
808 TT.fd = 1;
813 if (TT.f && strcmp(TT.f, "-"))
814 TT.fd = xcreate(TT.f, TT.fd*(O_WRONLY|O_CREAT|O_TRUNC), 0666);
816 if (TT.C) xchdir(TT.C);
820 TT.cwd = xabspath(s = xgetcwd(), 1);
827 if (!fstat(TT.fd, &st)) {
828 TT.aino = st.st_ino;
829 TT.adev = st.st_dev;
839 len = xread(TT.fd, hdr = toybuf+sizeof(toybuf)-512, 512);
848 if (!lseek(TT.fd, -len, SEEK_CUR)) hdr = 0;
853 int pipefd[2] = {hdr ? -1 : TT.fd, -1}, i, pid;
864 close(TT.fd);
865 TT.fd = pipefd[1];
870 // we have to loop reading data from TT.fd and pass it to gzip ourselves
887 if ((i = read(TT.fd, toybuf, sizeof(toybuf)))<1) {
900 // Each time a TT.incl entry is seen it's moved to the end of the list,
901 // with TT.seen pointing to first seen list entry. Anything between
902 // TT.incl and TT.seen wasn't encountered in archive..
903 if (TT.seen != TT.incl) {
904 if (!TT.seen) TT.seen = TT.incl;
905 while (TT.incl != TT.seen) {
906 error_msg("'%s' not in archive", TT.incl->data);
907 TT.incl = TT.incl->next;
913 struct double_list *dl = TT.incl;
916 if (TT.f && !FLAG(j) && !FLAG(z)) {
918 if (strend(TT.f, ".tgz") || strend(TT.f, ".tar.gz"))
920 if (strend(TT.f, ".txz") || strend(TT.f, ".tar.xz"))
923 if (strend(TT.f, tbz[len])) toys.optflags |= FLAG_j;
927 int pipefd[2] = {-1, TT.fd};
930 close(TT.fd);
931 TT.fd = pipefd[0];
934 TT.warn = 1;
936 } while (TT.incl != (dl = dl->next));
938 writeall(TT.fd, toybuf, 1024);
942 llist_traverse(TT.excl, llist_free_double);
943 llist_traverse(TT.incl, llist_free_double);
944 while(TT.hlc) free(TT.hlx[--TT.hlc].arg);
945 free(TT.hlx);
946 free(TT.cwd);
947 close(TT.fd);