summaryrefslogtreecommitdiff
path: root/dpkg-split
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2010-02-27 19:55:25 +0100
committerGuillem Jover <guillem@debian.org>2010-03-06 10:41:40 +0100
commit62668eb422853854976560949f95a5afcc6a8677 (patch)
tree3865d678367a07dd7aec0ef6aee009801b402c9b /dpkg-split
parent9d81bf92ef791ad4644f36d3b5f7361e883134d6 (diff)
downloaddpkg-62668eb422853854976560949f95a5afcc6a8677.tar.gz
Do an fsync on files written to disk
This guarantees the file contents will be there in case of abrupt program termination (due to crashes for example, or user intervention). This also guarantees the atomicity of rename(2) calls. Closes: #430958 Based-on-patch-by: Jean-Baptiste Lallement <jeanbaptiste.lallement@gmail.com>
Diffstat (limited to 'dpkg-split')
-rw-r--r--dpkg-split/join.c5
-rw-r--r--dpkg-split/queue.c4
2 files changed, 9 insertions, 0 deletions
diff --git a/dpkg-split/join.c b/dpkg-split/join.c
index 6b200d846..97b6cd670 100644
--- a/dpkg-split/join.c
+++ b/dpkg-split/join.c
@@ -24,6 +24,7 @@
#include <assert.h>
#include <limits.h>
#include <string.h>
+#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
@@ -68,6 +69,10 @@ void reassemble(struct partinfo **partlist, const char *outputfile) {
nr= fwrite(buffer,1,pi->thispartlen,output);
if (nr != pi->thispartlen) werr(outputfile);
}
+ if (fflush(output))
+ ohshite(_("unable to flush file '%s'"), outputfile);
+ if (fsync(fileno(output)))
+ ohshite(_("unable to sync file '%s'"), outputfile);
if (fclose(output)) werr(outputfile);
printf(_("done\n"));
}
diff --git a/dpkg-split/queue.c b/dpkg-split/queue.c
index ed114e61e..dae30c445 100644
--- a/dpkg-split/queue.c
+++ b/dpkg-split/queue.c
@@ -166,6 +166,10 @@ void do_auto(const char *const *argv) {
if (!part) ohshite(_("unable to open new depot file `%.250s'"),p);
nr= fwrite(buffer,1,refi->filesize,part);
if (nr != refi->filesize) werr(p);
+ if (fflush(part))
+ ohshite(_("unable to flush file '%s'"), p);
+ if (fsync(fileno(part)))
+ ohshite(_("unable to sync file '%s'"), p);
if (fclose(part)) werr(p);
if (rename(p,q)) ohshite(_("unable to rename new depot file `%.250s' to `%.250s'"),p,q);