From 9c2b86fec61202975f81b0a9b6721fa46e6a85d7 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 8 Feb 2011 08:27:22 +1100 Subject: [PATCH] We are flushing the wrong file on decompression. Make sure we flush the file out. --- main.c | 2 ++ rzip.h | 1 + stream.c | 6 ++---- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 5a8b5ae..daa94ff 100644 --- a/main.c +++ b/main.c @@ -292,6 +292,7 @@ static void decompress_file(void) preserve_perms(fd_in, fd_out); } else fd_out = open_tmpoutfile(); + control.fd_out = fd_out; fd_hist = open(control.outfile, O_RDONLY); if (unlikely(fd_hist == -1)) @@ -490,6 +491,7 @@ static void compress_file(void) fatal("Failed to create %s: %s\n", control.outfile, strerror(errno)); } else fd_out = open_tmpoutfile(); + control.fd_out = fd_out; preserve_perms(fd_in, fd_out); diff --git a/rzip.h b/rzip.h index 3094d57..2f6dd79 100644 --- a/rzip.h +++ b/rzip.h @@ -266,6 +266,7 @@ struct rzip_control { int minor_version; i64 st_size; long page_size; + int fd_out; } control; struct stream { diff --git a/stream.c b/stream.c index fad5886..fbbf5b7 100644 --- a/stream.c +++ b/stream.c @@ -43,7 +43,6 @@ struct uncomp_thread{ sem_t ready; /* Taken this thread's data so it can die */ sem_t free; int stream; - int fd; } *ucthread; void init_sem(sem_t *sem) @@ -969,7 +968,7 @@ static void *compthread(void *t) cti->c_type = CTYPE_NONE; cti->c_len = cti->s_len; - /* Flushing writes to disk, frees up any dirty ram, improving chances + /* Flushing writes to disk frees up any dirty ram, improving chances * of succeeding in allocating more ram */ fsync(ctis->fd); retry: @@ -1095,7 +1094,6 @@ static void *ucompthread(void *t) if (unlikely(setpriority(PRIO_PROCESS, 0, control.nice_val) == -1)) print_err("Warning, unable to set nice value on thread\n"); - fsync(uci->fd); retry: if (uci->c_type != CTYPE_NONE) { switch (uci->c_type) { @@ -1190,6 +1188,7 @@ fill_another: /* Wait till the next thread is free */ wait_sem(&ucthread[s->uthread_no].free); + fsync(control.fd_out); s_buf = malloc(u_len); if (unlikely(u_len && !s_buf)) @@ -1205,7 +1204,6 @@ fill_another: ucthread[s->uthread_no].u_len = u_len; ucthread[s->uthread_no].c_type = c_type; ucthread[s->uthread_no].stream = stream; - ucthread[s->uthread_no].fd = sinfo->fd; s->last_head = last_head; print_maxverbose("Starting thread %ld to decompress %lld bytes from stream %d\n",