Use "use warnings" rather than -w on the #! line.
[rsync/rsync-patches.git] / fsync.diff
CommitLineData
edd5f785
WD
1This patch from Sami Farin lets you specify --fsync if you want fsync()
2to be called on every file we write.
3
03019e41
WD
4To use this patch, run these commands for a successful build:
5
6 patch -p1 <patches/fsync.diff
7 ./configure (optional if already run)
8 make
9
cc3e685d
WD
10diff --git a/options.c b/options.c
11--- a/options.c
12+++ b/options.c
c0c7984e 13@@ -48,6 +48,7 @@ int append_mode = 0;
125d7fca 14 int keep_dirlinks = 0;
d42637db 15 int copy_dirlinks = 0;
edd5f785 16 int copy_links = 0;
994f69cd
WD
17+int do_fsync = 0;
18 int preserve_links = 0;
19 int preserve_hard_links = 0;
87a38eea 20 int preserve_acls = 0;
abd3adb8 21@@ -384,6 +385,7 @@ void usage(enum logcode F)
a7219d20
WD
22 rprintf(F," --partial-dir=DIR put a partially transferred file into DIR\n");
23 rprintf(F," --delay-updates put all updated files into place at transfer's end\n");
4a65fe72 24 rprintf(F," -m, --prune-empty-dirs prune empty directory chains from the file-list\n");
edd5f785 25+ rprintf(F," --fsync fsync every written file\n");
a7219d20 26 rprintf(F," --numeric-ids don't map uid/gid values by user/group name\n");
cc3e685d
WD
27 rprintf(F," --timeout=SECONDS set I/O timeout in seconds\n");
28 rprintf(F," --contimeout=SECONDS set daemon connection timeout in seconds\n");
abd3adb8 29@@ -627,6 +629,7 @@ static struct poptOption long_options[] = {
790ba11a 30 {"no-timeout", 0, POPT_ARG_VAL, &io_timeout, 0, 0, 0 },
cc3e685d 31 {"contimeout", 0, POPT_ARG_INT, &connect_timeout, 0, 0, 0 },
c0c7984e 32 {"no-contimeout", 0, POPT_ARG_VAL, &connect_timeout, 0, 0, 0 },
790ba11a
WD
33+ {"fsync", 0, POPT_ARG_NONE, &do_fsync, 0, 0, 0 },
34 {"rsh", 'e', POPT_ARG_STRING, &shell_cmd, 0, 0, 0 },
35 {"rsync-path", 0, POPT_ARG_STRING, &rsync_path, 0, 0, 0 },
36 {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
abd3adb8 37@@ -2019,6 +2022,9 @@ void server_options(char **args, int *argc_p)
80c89075
WD
38 args[ac++] = tmpdir;
39 }
7b675ff5 40
80c89075
WD
41+ if (do_fsync)
42+ args[ac++] = "--fsync";
7b675ff5 43+
80c89075
WD
44 if (basis_dir[0]) {
45 /* the server only needs this option if it is not the sender,
46 * and it may be an older version that doesn't know this
cc3e685d
WD
47diff --git a/receiver.c b/receiver.c
48--- a/receiver.c
49+++ b/receiver.c
5795bf59 50@@ -39,6 +39,7 @@ extern int relative_paths;
b76d92e6 51 extern int preserve_hard_links;
f6c3b300 52 extern int preserve_perms;
5795bf59 53 extern int preserve_xattrs;
edd5f785 54+extern int do_fsync;
1d15f8d9
WD
55 extern int basis_dir_cnt;
56 extern int make_backups;
57 extern int cleanup_got_literal;
abd3adb8 58@@ -302,6 +303,12 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
7b675ff5
WD
59 exit_cleanup(RERR_FILEIO);
60 }
edd5f785 61
67c08134 62+ if (do_fsync && fd != -1 && fsync(fd) != 0) {
7b675ff5 63+ rsyserr(FERROR, errno, "fsync failed on %s",
fe6407b5 64+ full_fname(fname));
edd5f785
WD
65+ exit_cleanup(RERR_FILEIO);
66+ }
67+
87a38eea 68 sum_len = sum_end(file_sum1);
edd5f785 69
dc3ae351 70 if (mapbuf)
cc3e685d
WD
71diff --git a/t_stub.c b/t_stub.c
72--- a/t_stub.c
73+++ b/t_stub.c
87a38eea 74@@ -21,6 +21,7 @@
7cf8a551
WD
75
76 #include "rsync.h"
d9a67109
WD
77
78+int do_fsync = 0;
79 int modify_window = 0;
01c39596 80 int module_id = -1;
56208f7b 81 int relative_paths = 0;
cc3e685d
WD
82diff --git a/util.c b/util.c
83--- a/util.c
84+++ b/util.c
85@@ -26,6 +26,7 @@
91f798a7
WD
86 extern int verbose;
87 extern int dry_run;
56208f7b 88 extern int module_id;
91f798a7 89+extern int do_fsync;
7b675ff5 90 extern int modify_window;
56208f7b 91 extern int relative_paths;
91f798a7 92 extern int human_readable;
91270139 93@@ -334,6 +335,13 @@ int copy_file(const char *source, const char *dest, int ofd,
71c2e1b2 94 full_fname(source));
7b675ff5 95 }
edd5f785 96
7b675ff5
WD
97+ if (do_fsync && fsync(ofd) < 0) {
98+ rsyserr(FERROR, errno, "fsync failed on %s",
fe6407b5 99+ full_fname(dest));
6cf4b26e 100+ close(ofd);
edd5f785
WD
101+ return -1;
102+ }
103+
71c2e1b2 104 if (close(ofd) < 0) {
91270139 105 int save_errno = errno;
cc3e685d 106 rsyserr(FERROR_XFER, errno, "close failed on %s",