Reinstate the temporary file for decompression from stdin. Seeking makes that option broken without the temporary file.

Start documenting the new features in this version.
Minor tidying.
This commit is contained in:
Con Kolivas 2010-11-01 21:37:55 +11:00
parent ba1bf30d78
commit 0e09c9ec24
3 changed files with 58 additions and 11 deletions

View file

@ -1,3 +1,15 @@
lrzip-0.50
Rewrote the file format to be up to 5% more compact and slightly faster.
Made the memory initialisation much more robust, with attempted fallback
to still work even when initial settings fail.
Fixed a lot of the stdin/stdout code.
The two most common scenarios now work without temporary files:
Compression from stdin and decompression to stdout.
Testing of archive integrity no longer writes any temporary files.
Lots more meaningful warnings if failure occurs.
Lots of code cleanups and tidying.
lrzip-0.46
Added lrzuntar which works the same as lrztar -d.

45
main.c
View file

@ -136,7 +136,7 @@ static void preserve_perms(int fd_in, int fd_out)
fchown(fd_out, st.st_uid, st.st_gid);
}
/* Open a temporary outputfile for testing decompression or msgout */
/* Open a temporary outputfile for stdout compression */
static int open_tmpoutfile(void)
{
int fd_out;
@ -174,6 +174,41 @@ static void dump_tmpoutfile(int fd_out)
fflush(control.msgout);
}
/* Open a temporary inputfile to perform stdin decompression */
static int open_tmpinfile(void)
{
int fd_in;
control.infile = malloc(15);
strcpy(control.infile, "lrzipin.XXXXXX");
if (!control.infile)
fatal("Failed to allocate infile name\n");
fd_in = mkstemp(control.infile);
if (fd_in == -1)
fatal("Failed to create in tmpfile: %s\n", strerror(errno));
return fd_in;
}
/* Read data from stdin into temporary inputfile */
static void read_tmpinfile(int fd_in)
{
FILE *tmpinfp;
int tmpchar;
if (control.flags & FLAG_SHOW_PROGRESS)
fprintf(control.msgout, "Copying from stdin.\n");
tmpinfp = fdopen(fd_in, "w+");
if (tmpinfp == NULL)
fatal("Failed to fdopen in tmpfile: %s\n", strerror(errno));
while ((tmpchar = getchar()) != EOF)
fputc(tmpchar, tmpinfp);
fflush(tmpinfp);
rewind(tmpinfp);
}
/*
decompress one file from the command line
*/
@ -235,7 +270,8 @@ static void decompress_file(void)
}
if (STDIN) {
fd_in = 0;
fd_in = open_tmpinfile();
read_tmpinfile(fd_in);
} else {
fd_in = open(infilecopy, O_RDONLY);
if (fd_in == -1) {
@ -282,10 +318,9 @@ static void decompress_file(void)
fatal("Failed to close files\n");
}
if (!STDIN)
close(fd_in);
close(fd_in);
if (!(KEEP_FILES | TEST_ONLY)) {
if (!(KEEP_FILES | TEST_ONLY) || STDIN) {
if (unlink(control.infile) != 0)
fatal("Failed to unlink %s: %s\n", infilecopy, strerror(errno));
}

View file

@ -134,7 +134,7 @@ static void zpaq_compress_buf(struct stream *s, int *c_type, i64 *c_len)
if (!out)
fatal("Failed to open_memstream in zpaq_compress_buf\n");
zpipe_compress(in, out, control.msgout, s->buflen, (int)(control.flags & FLAG_SHOW_PROGRESS));
zpipe_compress(in, out, control.msgout, s->buflen, (int)(SHOW_PROGRESS));
if (memstream_update_buffer(out, &c_buf, &dlen) != 0)
fatal("Failed to memstream_update_buffer in zpaq_compress_buf");
@ -331,7 +331,7 @@ static int zpaq_decompress_buf(struct stream *s)
return -1;
}
zpipe_decompress(in, out, control.msgout, s->buflen, (int)(control.flags & FLAG_SHOW_PROGRESS));
zpipe_decompress(in, out, control.msgout, s->buflen, (int)(SHOW_PROGRESS));
if (memstream_update_buffer(out, &c_buf, &dlen) != 0)
fatal("Failed to memstream_update_buffer in zpaq_decompress_buf");
@ -615,7 +615,7 @@ void *open_stream_out(int f, int n, i64 limit)
however, the larger the buffer, the better the compression so we
make it as large as the window up to the limit the compressor
will take */
if (LZMA_COMPRESS(control.flags)) {
if (LZMA_COMPRESS) {
if (sizeof(long) == 4) {
/* Largest window supported on lzma 32bit is 600MB */
if (cwindow > 6)
@ -626,7 +626,7 @@ void *open_stream_out(int f, int n, i64 limit)
cwindow = 40;
}
if (LZMA_COMPRESS(control.flags) || (control.flags & FLAG_ZPAQ_COMPRESS))
if (LZMA_COMPRESS || ZPAQ_COMPRESS)
sinfo->bufsize = STREAM_BUFSIZE * 10 * cwindow;
else
sinfo->bufsize = STREAM_BUFSIZE;
@ -768,8 +768,8 @@ static int flush_buffer(struct stream_info *sinfo, int stream)
if (seekto(sinfo, sinfo->cur_pos) != 0)
return -1;
if (!(control.flags & FLAG_NO_COMPRESS)) {
if (LZMA_COMPRESS(control.flags))
if (!(NO_COMPRESS)) {
if (LZMA_COMPRESS)
lzma_compress_buf(&sinfo->s[stream], &c_type, &c_len);
else if (LZO_COMPRESS)
lzo_compress_buf(&sinfo->s[stream], &c_type, &c_len);