mirror of
https://github.com/ckolivas/lrzip.git
synced 2025-12-06 07:12:00 +01:00
Attempt to decompress file in ram only if we are unable to create temporary files when decompressing to stdout
This commit is contained in:
parent
c3bc42e2c8
commit
8551a43c73
41
lrzip.c
41
lrzip.c
|
|
@ -314,9 +314,11 @@ int open_tmpoutfile(rzip_control *control)
|
||||||
}
|
}
|
||||||
|
|
||||||
fd_out = mkstemp(control->outfile);
|
fd_out = mkstemp(control->outfile);
|
||||||
if (unlikely(fd_out == -1))
|
if (fd_out == -1) {
|
||||||
fatal_return(("Failed to create out tmpfile: %s\n", control->outfile), -1);
|
print_verbose("WARNING: Failed to create out tmpfile: %s , will fail if cannot perform entirely in ram\n",
|
||||||
register_outfile(control, control->outfile, TEST_ONLY || STDOUT || !KEEP_BROKEN);
|
control->outfile, DECOMPRESS ? "de" : "");
|
||||||
|
} else
|
||||||
|
register_outfile(control, control->outfile, TEST_ONLY || STDOUT || !KEEP_BROKEN);
|
||||||
return fd_out;
|
return fd_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -352,7 +354,7 @@ bool write_fdout(rzip_control *control, void *buf, i64 len)
|
||||||
ret = MIN(len, one_g);
|
ret = MIN(len, one_g);
|
||||||
ret = write(control->fd_out, offset_buf, (size_t)ret);
|
ret = write(control->fd_out, offset_buf, (size_t)ret);
|
||||||
if (unlikely(ret <= 0))
|
if (unlikely(ret <= 0))
|
||||||
fatal_return(("Failed to write to fd_out in write_fdout\n"), false);;
|
fatal_return(("Failed to write to fd_out in write_fdout\n"), false);
|
||||||
len -= ret;
|
len -= ret;
|
||||||
offset_buf += ret;
|
offset_buf += ret;
|
||||||
}
|
}
|
||||||
|
|
@ -382,6 +384,8 @@ bool dump_tmpoutfile(rzip_control *control, int fd_out)
|
||||||
FILE *tmpoutfp;
|
FILE *tmpoutfp;
|
||||||
int tmpchar;
|
int tmpchar;
|
||||||
|
|
||||||
|
if (unlikely(fd_out == -1))
|
||||||
|
fatal_return(("Failed: No temporary outfile created, unable to do in ram\n"), false);
|
||||||
/* flush anything not yet in the temporary file */
|
/* flush anything not yet in the temporary file */
|
||||||
fsync(fd_out);
|
fsync(fd_out);
|
||||||
tmpoutfp = fdopen(fd_out, "r");
|
tmpoutfp = fdopen(fd_out, "r");
|
||||||
|
|
@ -742,14 +746,16 @@ bool decompress_file(rzip_control *control)
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
fd_out = open_tmpoutfile(control);
|
fd_out = open_tmpoutfile(control);
|
||||||
if (unlikely(fd_out == -1))
|
if (fd_out == -1) {
|
||||||
fatal_return(("Failed to create %s\n", control->outfile), false);
|
fd_hist = -1;
|
||||||
fd_hist = open(control->outfile, O_RDONLY);
|
} else {
|
||||||
if (unlikely(fd_hist == -1))
|
fd_hist = open(control->outfile, O_RDONLY);
|
||||||
fatal_return(("Failed to open history file %s\n", control->outfile), false);
|
if (unlikely(fd_hist == -1))
|
||||||
/* Unlink temporary file as soon as possible */
|
fatal_return(("Failed to open history file %s\n", control->outfile), false);
|
||||||
if (unlikely(unlink(control->outfile)))
|
/* Unlink temporary file as soon as possible */
|
||||||
fatal_return(("Failed to unlink tmpfile: %s\n", control->outfile), false);
|
if (unlikely(unlink(control->outfile)))
|
||||||
|
fatal_return(("Failed to unlink tmpfile: %s\n", control->outfile), false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlikely(!open_tmpoutbuf(control)))
|
if (unlikely(!open_tmpoutbuf(control)))
|
||||||
|
|
@ -759,7 +765,7 @@ bool decompress_file(rzip_control *control)
|
||||||
if (unlikely(!read_magic(control, fd_in, &expected_size)))
|
if (unlikely(!read_magic(control, fd_in, &expected_size)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!STDOUT) {
|
if (!STDOUT && !TEST_ONLY) {
|
||||||
/* Check if there's enough free space on the device chosen to fit the
|
/* Check if there's enough free space on the device chosen to fit the
|
||||||
* decompressed file. */
|
* decompressed file. */
|
||||||
if (unlikely(fstatvfs(fd_out, &fbuf)))
|
if (unlikely(fstatvfs(fd_out, &fbuf)))
|
||||||
|
|
@ -792,9 +798,10 @@ bool decompress_file(rzip_control *control)
|
||||||
if (unlikely(runzip_fd(control, fd_in, fd_out, fd_hist, expected_size) < 0))
|
if (unlikely(runzip_fd(control, fd_in, fd_out, fd_hist, expected_size) < 0))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (STDOUT && !TMP_OUTBUF)
|
if (STDOUT && !TMP_OUTBUF) {
|
||||||
if (unlikely(!dump_tmpoutfile(control, fd_out)))
|
if (unlikely(!dump_tmpoutfile(control, fd_out)))
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* if we get here, no fatal_return(( errors during decompression */
|
/* if we get here, no fatal_return(( errors during decompression */
|
||||||
print_progress("\r");
|
print_progress("\r");
|
||||||
|
|
@ -807,8 +814,10 @@ bool decompress_file(rzip_control *control)
|
||||||
else
|
else
|
||||||
print_progress("[OK] \n");
|
print_progress("[OK] \n");
|
||||||
|
|
||||||
if (unlikely(close(fd_hist) || close(fd_out)))
|
if (fd_out > 0) {
|
||||||
fatal_return(("Failed to close files\n"), false);
|
if (unlikely(close(fd_hist) || close(fd_out)))
|
||||||
|
fatal_return(("Failed to close files\n"), false);
|
||||||
|
}
|
||||||
|
|
||||||
if (unlikely(!STDIN && !STDOUT && !TEST_ONLY && !preserve_times(control, fd_in)))
|
if (unlikely(!STDIN && !STDOUT && !TEST_ONLY && !preserve_times(control, fd_in)))
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
28
runzip.c
28
runzip.c
|
|
@ -379,20 +379,30 @@ i64 runzip_fd(rzip_control *control, int fd_in, int fd_out, int fd_hist, i64 exp
|
||||||
|
|
||||||
do {
|
do {
|
||||||
u = runzip_chunk(control, fd_in, expected_size, total);
|
u = runzip_chunk(control, fd_in, expected_size, total);
|
||||||
if (unlikely(u == -1))
|
if (unlikely(u == -1)) {
|
||||||
|
print_err("Failed to runzip_chunk in runzip_fd\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
total += u;
|
total += u;
|
||||||
if (TMP_OUTBUF)
|
if (TMP_OUTBUF) {
|
||||||
{ if (unlikely(!flush_tmpoutbuf(control)))
|
if (unlikely(!flush_tmpoutbuf(control))) {
|
||||||
return -1; }
|
print_err("Failed to flush_tmpoutbuf in runzip_fd\n");
|
||||||
else if (STDOUT)
|
return -1;
|
||||||
{ if (unlikely(!dump_tmpoutfile(control, fd_out)))
|
}
|
||||||
return -1; }
|
} else if (STDOUT) {
|
||||||
|
if (unlikely(!dump_tmpoutfile(control, fd_out))) {
|
||||||
|
print_err("Failed to dump_tmpoutfile in runzip_fd\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (TMP_INBUF)
|
if (TMP_INBUF)
|
||||||
clear_tmpinbuf(control);
|
clear_tmpinbuf(control);
|
||||||
else if (STDIN && !DECOMPRESS)
|
else if (STDIN && !DECOMPRESS) {
|
||||||
if (unlikely(!clear_tmpinfile(control)))
|
if (unlikely(!clear_tmpinfile(control))) {
|
||||||
|
print_err("Failed to clear_tmpinfile in runzip_fd\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
} while (total < expected_size || (!expected_size && !control->eof));
|
} while (total < expected_size || (!expected_size && !control->eof));
|
||||||
|
|
||||||
gettimeofday(&end,NULL);
|
gettimeofday(&end,NULL);
|
||||||
|
|
|
||||||
3
rzip.c
3
rzip.c
|
|
@ -1179,11 +1179,12 @@ retry:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TMP_OUTBUF)
|
if (TMP_OUTBUF) {
|
||||||
if (unlikely(!flush_tmpoutbuf(control))) {
|
if (unlikely(!flush_tmpoutbuf(control))) {
|
||||||
free(st);
|
free(st);
|
||||||
failure("Failed to flush_tmpoutbuf in rzip_fd\n");
|
failure("Failed to flush_tmpoutbuf in rzip_fd\n");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gettimeofday(¤t, NULL);
|
gettimeofday(¤t, NULL);
|
||||||
if (STDIN)
|
if (STDIN)
|
||||||
|
|
|
||||||
14
stream.c
14
stream.c
|
|
@ -619,11 +619,17 @@ ssize_t put_fdout(rzip_control *control, void *offset_buf, ssize_t ret)
|
||||||
/* The data won't fit in a temporary output buffer so we have
|
/* The data won't fit in a temporary output buffer so we have
|
||||||
* to fall back to temporary files. */
|
* to fall back to temporary files. */
|
||||||
print_verbose("Unable to decompress entirely in ram, will use physical files\n");
|
print_verbose("Unable to decompress entirely in ram, will use physical files\n");
|
||||||
if (unlikely(!write_fdout(control, control->tmp_outbuf, control->out_len)))
|
if (unlikely(control->fd_out == -1))
|
||||||
|
failure("Was unable to decompress entirely in ram and no temporary file creation was possible\n");
|
||||||
|
if (unlikely(!write_fdout(control, control->tmp_outbuf, control->out_len))) {
|
||||||
|
print_err("Unable to write_fdout tmpoutbuf in put_fdout\n");
|
||||||
return -1;
|
return -1;
|
||||||
close_tmpoutbuf(control);
|
}
|
||||||
|
close_tmpoutbuf(control); {
|
||||||
if (unlikely(!write_fdout(control, offset_buf, ret)))
|
if (unlikely(!write_fdout(control, offset_buf, ret)))
|
||||||
|
print_err("Unable to write_fdout offset_buf in put_fdout\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
memcpy(control->tmp_outbuf + control->out_ofs, offset_buf, ret);
|
memcpy(control->tmp_outbuf + control->out_ofs, offset_buf, ret);
|
||||||
|
|
@ -1334,8 +1340,10 @@ retry:
|
||||||
write_magic(control);
|
write_magic(control);
|
||||||
unlock_mutex(control, &control->control_lock);
|
unlock_mutex(control, &control->control_lock);
|
||||||
|
|
||||||
if (unlikely(!flush_tmpoutbuf(control)))
|
if (unlikely(!flush_tmpoutbuf(control))) {
|
||||||
|
print_err("Failed to flush_tmpoutbuf in compthread\n");
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print_maxverbose("Writing initial chunk bytes value %d at %lld\n",
|
print_maxverbose("Writing initial chunk bytes value %d at %lld\n",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue