void th_set_from_stat(TAR *t, struct stat *s) { th_set_type(t, s->st_mode); if (S_ISCHR(s->st_mode) || S_ISBLK(s->st_mode)) th_set_device(t, s->st_rdev); th_set_user(t, s->st_uid); th_set_group(t, s->st_gid); th_set_mode(t, s->st_mode); th_set_mtime(t, s->st_mtime); if (S_ISREG(s->st_mode)) th_set_size(t, s->st_size); else th_set_size(t, 0); }
static int do_delete(struct dirent *d) { int ret; struct stat sb; char realname[PATH_MAX]; char savename[PATH_MAX]; sprintf(realname, "%s%s/%s", base1, prefix, d->d_name); sprintf(savename, "%s%s/%s", "delete", prefix, d->d_name); if(d->d_type == DT_DIR) { DIR *dir; struct dirent *dp; int len = strlen(prefix); strcat(prefix, "/"); strcat(prefix, d->d_name); dir = opendir(realname); while ((dp = readdir(dir)) != NULL) { if (!filter(dp)) continue; do_delete(dp); } prefix[len] = 0; } fprintf(stderr, "%s/%s was deleted\n", prefix, d->d_name); if(!t) return 0; ret = lstat(realname, &sb); th_set_from_stat(t, &sb); th_set_path(t, savename); th_set_size(t, 0); th_finish(t); if(t->options & TAR_VERBOSE) th_print_long_ls(t); th_write(t); }
static int do_diff(struct dirent *d1, struct dirent *d2) { int ret; struct stat sb; char realname1[PATH_MAX]; char realname2[PATH_MAX]; char savename[PATH_MAX]; //char cmd[4096]; fprintf(stderr, "%s/%s differs\n", prefix, d1->d_name); if(!t) return 0; sprintf(realname1, "%s%s/%s", base1, prefix, d1->d_name); sprintf(realname2, "%s%s/%s", base2, prefix, d2->d_name); sprintf(savename, "%s%s/%s", "diff", prefix, d1->d_name); //sprintf(cmd, "cp %s patch", realname2); //sprintf(cmd, "/home/stephan/rdiff %s %s patch", realname1, realname2); //sprintf(cmd, "/usr/bin/xdelta3 -e -s %s %s patch", realname1, realname2); //sprintf(cmd, "/usr/bin/xdelta3 -e -S djw -9 -s %s %s patch", realname1, realname2); //sprintf(cmd, "/usr/bin/bsdiff %s %s patch", realname1, realname2); //sprintf(cmd, "/home/stephan/src/fsdiff/bsdiff %s %s patch", realname1, realname2); //system(cmd); bsdiff(realname1, realname2, "patch"); ret = lstat(realname2, &sb); th_set_from_stat(t, &sb); th_set_path(t, savename); ret = lstat("patch", &sb); th_set_size(t, sb.st_size); th_finish(t); if(t->options & TAR_VERBOSE) th_print_long_ls(t); th_write(t); tar_append_regfile(t, "patch"); //system("rm patch"); unlink("patch"); }
/* write a header block */ int th_write(TAR *t) { int i, j; char type2; size_t sz, sz2; char *ptr; char buf[T_BLOCKSIZE]; #ifdef DEBUG printf("==> th_write(TAR=\"%s\")\n", t->pathname); th_print(t); #endif if ((t->options & TAR_GNU) && t->th_buf.gnu_longlink != NULL) { #ifdef DEBUG printf("th_write(): using gnu_longlink (\"%s\")\n", t->th_buf.gnu_longlink); #endif /* save old size and type */ type2 = t->th_buf.typeflag; sz2 = th_get_size(t); /* write out initial header block with fake size and type */ t->th_buf.typeflag = GNU_LONGLINK_TYPE; sz = strlen(t->th_buf.gnu_longlink); th_set_size(t, sz); th_finish(t); i = tar_block_write(t, &(t->th_buf)); if (i != T_BLOCKSIZE) { if (i != -1) errno = EINVAL; return -1; } /* write out extra blocks containing long name */ for (j = (sz / T_BLOCKSIZE) + (sz % T_BLOCKSIZE ? 1 : 0), ptr = t->th_buf.gnu_longlink; j > 1; j--, ptr += T_BLOCKSIZE) { i = tar_block_write(t, ptr); if (i != T_BLOCKSIZE) { if (i != -1) errno = EINVAL; return -1; } } memset(buf, 0, T_BLOCKSIZE); strncpy(buf, ptr, T_BLOCKSIZE); i = tar_block_write(t, &buf); if (i != T_BLOCKSIZE) { if (i != -1) errno = EINVAL; return -1; } /* reset type and size to original values */ t->th_buf.typeflag = type2; th_set_size(t, sz2); } if ((t->options & TAR_GNU) && t->th_buf.gnu_longname != NULL) { #ifdef DEBUG printf("th_write(): using gnu_longname (\"%s\")\n", t->th_buf.gnu_longname); #endif /* save old size and type */ type2 = t->th_buf.typeflag; sz2 = th_get_size(t); /* write out initial header block with fake size and type */ t->th_buf.typeflag = GNU_LONGNAME_TYPE; sz = strlen(t->th_buf.gnu_longname); th_set_size(t, sz); th_finish(t); i = tar_block_write(t, &(t->th_buf)); if (i != T_BLOCKSIZE) { if (i != -1) errno = EINVAL; return -1; } /* write out extra blocks containing long name */ for (j = (sz / T_BLOCKSIZE) + (sz % T_BLOCKSIZE ? 1 : 0), ptr = t->th_buf.gnu_longname; j > 1; j--, ptr += T_BLOCKSIZE) { i = tar_block_write(t, ptr); if (i != T_BLOCKSIZE) { if (i != -1) errno = EINVAL; return -1; } } memset(buf, 0, T_BLOCKSIZE); strncpy(buf, ptr, T_BLOCKSIZE); i = tar_block_write(t, &buf); if (i != T_BLOCKSIZE) { if (i != -1) errno = EINVAL; return -1; } /* reset type and size to original values */ t->th_buf.typeflag = type2; th_set_size(t, sz2); } th_finish(t); #ifdef DEBUG /* print tar header */ th_print(t); #endif i = tar_block_write(t, &(t->th_buf)); if (i != T_BLOCKSIZE) { if (i != -1) errno = EINVAL; return -1; } #ifdef DEBUG puts("th_write(): returning 0"); #endif return 0; }