mirror of
https://github.com/ckolivas/lrzip.git
synced 2026-03-20 19:54:37 +01:00
Check for free space before compression/decompression and abort if -f option is not enabled.
This commit is contained in:
parent
3433438a8e
commit
8bdd5688c8
15
main.c
15
main.c
|
|
@ -255,7 +255,8 @@ static void decompress_file(void)
|
|||
{
|
||||
char *tmp, *tmpoutfile, *infilecopy = NULL;
|
||||
int fd_in, fd_out = -1, fd_hist = -1;
|
||||
i64 expected_size;
|
||||
i64 expected_size, free_space;
|
||||
struct statvfs fbuf;
|
||||
|
||||
if (!STDIN) {
|
||||
if ((tmp = strrchr(control.infile, '.')) && strcmp(tmp,control.suffix)) {
|
||||
|
|
@ -320,6 +321,18 @@ static void decompress_file(void)
|
|||
}
|
||||
}
|
||||
|
||||
/* Check if there's enough free space on the device chosen to fit the
|
||||
* decompressed file. */
|
||||
if (unlikely(fstatvfs(fd_in, &fbuf)))
|
||||
fatal("Failed to fstatvfs in decompress_file\n");
|
||||
free_space = fbuf.f_bsize * fbuf.f_bavail;
|
||||
if (free_space < expected_size) {
|
||||
if (FORCE_REPLACE)
|
||||
print_err("Warning, inadequate free space detected, but attempting to decompress due to -f option being used.\n");
|
||||
else
|
||||
failure("Inadequate free space to decompress file, use -f to override.\n");
|
||||
}
|
||||
|
||||
if (!(TEST_ONLY | STDOUT)) {
|
||||
if (FORCE_REPLACE)
|
||||
fd_out = open(control.outfile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
|
|
|
|||
15
rzip.c
15
rzip.c
|
|
@ -740,6 +740,8 @@ void rzip_fd(int fd_in, int fd_out)
|
|||
elapsed_minutes, elapsed_seconds;
|
||||
double finish_time, elapsed_time, chunkmbs;
|
||||
char md5_resblock[MD5_DIGEST_SIZE];
|
||||
struct statvfs fbuf;
|
||||
i64 free_space;
|
||||
|
||||
md5_init_ctx (&control.ctx);
|
||||
|
||||
|
|
@ -761,6 +763,19 @@ void rzip_fd(int fd_in, int fd_out)
|
|||
} else
|
||||
control.st_size = 0;
|
||||
|
||||
/* Check if there's enough free space on the device chosen to fit the
|
||||
* compressed file, based on the compressed file being as large as the
|
||||
* uncompressed file. */
|
||||
if (unlikely(fstatvfs(fd_in, &fbuf)))
|
||||
fatal("Failed to fstatvfs in decompress_file\n");
|
||||
free_space = fbuf.f_bsize * fbuf.f_bavail;
|
||||
if (free_space < control.st_size) {
|
||||
if (FORCE_REPLACE)
|
||||
print_err("Warning, possibly inadequate free space detected, but attempting to compress due to -f option being used.\n");
|
||||
else
|
||||
failure("Possibly inadequate free space to compress file, use -f to override.\n");
|
||||
}
|
||||
|
||||
/* Optimal use of ram involves using no more than 2/3 of it, so we
|
||||
* allocate 1/3 of it to the main buffer and use a sliding mmap
|
||||
* buffer to work on 2/3 ram size, leaving enough ram for the
|
||||
|
|
|
|||
Loading…
Reference in a new issue