[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: tar option suggestion
From: |
Jim Hefferon |
Subject: |
Re: tar option suggestion |
Date: |
Sun, 10 Mar 2002 14:37:00 GMT |
Paul,
Thanks again for your reply. I'm sorry; I do not find that the
--blocking-factor=1 helps me out.
Perhaps it is because of a pecularity in the way that I need to call the
tar program? I call tar from inside of a C program (because when a
user's browser asks for `/pub/packages/TeX/macros/texinfo.tar.gz'
the users want an archive containing only texinfo and its subdirectories,
so I first cd to the relevant place and then I tar). I've attached
the C program at the end (sorry about it; I'm not a C programmer) but the
relevant line is (we've already cd'ed and base is the directory basename):
} else if (argv[1][1]=='g') {
/* tgz the directory */
execl("/bin/tar","/bin/tar","-c","-z","-h","--blocking-factor=1","-f","-",base,NULL);
I did not believe that this mattered, so I mistakenly did not mention it
earlier. But it seems to matter. Here are a sequence of steps following
your suggestion and calling tar with blocking-factor=1, once inside of the
C program and once at the shell:
address@hidden archiver]# ./archiver -g
/home/ftp/pub/tex-archive/macros/latex/contrib/supported/beton > beton.tar.gz
address@hidden archiver]# tar xzf beton.tar.gz
gzip: stdin: decompression OK, trailing garbage ignored
tar: Child returned status 2
tar: Error exit delayed from previous errors
address@hidden archiver]# ls beton
beton.dtx beton.ins
address@hidden archiver]# tar --blocking-factor=1 -czf beton.tar.gz beton
address@hidden archiver]# mv beton beton.bak
address@hidden archiver]# tar xzf beton.tar.gz
address@hidden archiver]#
(this is a routine RedHat 6.1 system and the archiver.c program was compiled
as `gcc -oarchiver archiver.c' using gcc version: egcs-2.91.66). Changing
--blocking-factor=1 to -b1 inside the execlmakes no difference that I can see.
Sorry to be a pest, Paul; am I overlooking something that I should know?
Thanks,
Jim
===== source of archiver.c
/* archiver.c
Give a user the .zip (or .tar, or .tar.gz, or .tar.Z) file with
the directories suppressed.
When browsers come in, they act differently that command line
users. They don't cd to above the directory. So this program
breaks their path apart, cd's to above the directory, and
then issues the zip command. Else users get .zip files with
long directory prefixes like
tex-archive/macros/latex/contrib/beton
that don't match their TeX directory structures.
This replaces the shell script written by Robin Fairbairns.
2000-Sept Jim Hefferon address@hidden
Dec-06 JH Added y option
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#define STR_SIZE 500
int main(int argc, char ** argv) {
int i, j;
char dir[STR_SIZE+1];
char base[STR_SIZE+1];
int last_slash;
if (argc!=3) {
printf("Usage: archiver -[z,t,g,Z,y] path/to/dir\n");
return 1;
}
/* Find the final `/' if there is one, so we can break on it */
last_slash=-1;
i=0;
while ((i<STR_SIZE) && (argv[2][i]!='\0')) {
if (argv[2][i]=='/') {
last_slash=i;
}
i++;
}
/* Pull off the name of the directory to zip up */
i=last_slash+1;
j=0;
while ((i<STR_SIZE) && (argv[2][i]!='\0')) {
base[j]=argv[2][i];
i++;
j++;
}
base[j]='\0';
/* Pull off the path to that directory */
i=0;
while ((i<last_slash) && (argv[2][i]!='\0')) {
dir[i]=argv[2][i];
i++;
}
dir[i]='\0';
/* Move to above the directory to zip, if needed */
if (dir[0]!='\0') {
if (chdir(dir)!=0) {
return -2;
}
}
/* now send it out according to whether asked for -t, -g, -Z, or -z, or y */
if (argv[1][1]=='t') {
/* tar up the directory and send the result to stdio */
execl("/bin/tar","/bin/tar","-c","-h","-X/bin/excluded_files","-f","-",base,NULL);
} else if (argv[1][1]=='g') {
/* tgz the directory */
execl("/bin/tar","/bin/tar","-c","-z","-h","-b1","-f","-",base,NULL);
} else if (argv[1][1]=='Z') {
/* .tar.Z up the directory */
execl("/bin/tar","/bin/tar","-c","-Z","-h","-X/bin/excluded_files","-f","-",base,NULL);
} else if (argv[1][1]=='y') {
/* .zip up the directory; dont follow sym links */
execl("/bin/zip","/bin/zip","-r","-qq","-y","-",base,NULL);
} else {
/* zip up the directory */
execl("/bin/zip","/bin/zip","-r","-qq","-",base,NULL);
}
}
=========== this is run from /etc/ftpconversions, if that matters
:.Z: : :/bin/compress -d -c %s:T_REG|T_ASCII:O_UNCOMPRESS:UNCOMPRESS
: : :.Z:/bin/compress -c %s:T_REG:O_COMPRESS:COMPRESS
:.gz: : :/bin/gzip -cd %s:T_REG|T_ASCII:O_UNCOMPRESS:GUNZIP
: : :.gz:/bin/gzip -9 -c %s:T_REG:O_COMPRESS:GZIP
: : :.tar:/bin/archiver -t %s:T_REG|T_DIR:O_TAR:TAR
: : :.tar.Z:/bin/archiver -Z %s:T_REG|T_DIR:O_COMPRESS|O_TAR:TAR+COMPRESS
: : :.tar.z:/bin/archiver -g %s:T_REG|T_DIR:O_COMPRESS|O_TAR:TAR+COMPRESS
: : :.tar.gz:/bin/archiver -g %s:T_REG|T_DIR:O_COMPRESS|O_TAR:TAR+GZIP
: : :.tgz:/bin/archiver -g %s:T_REG|T_DIR:O_COMPRESS|O_TAR:TAR+GZIP
: : :.zip:/bin/archiver -z %s:T_REG|T_DIR:O_COMPRESS|O_TAR:ZIP