Fixed patch fuzz.
[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
a7219d20
WD
4--- orig/options.c 2005-02-01 10:39:22
5+++ options.c 2005-01-28 19:30:47
6@@ -39,6 +39,7 @@ int make_backups = 0;
edd5f785
WD
7 **/
8 int whole_file = -1;
9
10+int do_fsync = 0;
11 int archive_mode = 0;
125d7fca 12 int keep_dirlinks = 0;
edd5f785 13 int copy_links = 0;
a7219d20
WD
14@@ -294,6 +295,7 @@ void usage(enum logcode F)
15 rprintf(F," --partial keep partially transferred files\n");
16 rprintf(F," --partial-dir=DIR put a partially transferred file into DIR\n");
17 rprintf(F," --delay-updates put all updated files into place at transfer's end\n");
edd5f785 18+ rprintf(F," --fsync fsync every written file\n");
a7219d20
WD
19 rprintf(F," --numeric-ids don't map uid/gid values by user/group name\n");
20 rprintf(F," --timeout=TIME set I/O timeout in seconds\n");
21 rprintf(F," -I, --ignore-times don't skip files that match in size and mod-time\n");
22@@ -371,6 +373,7 @@ static struct poptOption long_options[]
edd5f785 23 {"safe-links", 0, POPT_ARG_NONE, &safe_symlinks, 0, 0, 0 },
57e73b72 24 {"help", 'h', POPT_ARG_NONE, 0, 'h', 0, 0 },
edd5f785
WD
25 {"backup", 'b', POPT_ARG_NONE, &make_backups, 0, 0, 0 },
26+ {"fsync", 0, POPT_ARG_NONE, &do_fsync, 0, 0, 0 },
27 {"dry-run", 'n', POPT_ARG_NONE, &dry_run, 0, 0, 0 },
28 {"sparse", 'S', POPT_ARG_NONE, &sparse_files, 0, 0, 0 },
29 {"cvs-exclude", 'C', POPT_ARG_NONE, &cvs_exclude, 0, 0, 0 },
a7219d20 30@@ -1293,6 +1296,9 @@ void server_options(char **args,int *arg
edd5f785
WD
31 args[ac++] = tmpdir;
32 }
7b675ff5 33
edd5f785
WD
34+ if (do_fsync && am_sender)
35+ args[ac++] = "--fsync";
7b675ff5 36+
0808daa5 37 if (basis_dir[0] && am_sender) {
edd5f785 38 /* the server only needs this option if it is not the sender,
7b675ff5 39 * and it may be an older version that doesn't know this
a7219d20 40--- orig/receiver.c 2005-02-03 02:04:20
f6c3b300 41+++ receiver.c 2004-07-16 20:13:31
a7219d20 42@@ -34,6 +34,7 @@ extern int keep_dirlinks;
b76d92e6 43 extern int preserve_hard_links;
f6c3b300 44 extern int preserve_perms;
f6c3b300 45 extern int io_error;
edd5f785 46+extern int do_fsync;
f6c3b300 47 extern char *tmpdir;
afbebe13 48 extern char *partial_dir;
0808daa5 49 extern char *basis_dir[];
a7219d20 50@@ -242,6 +243,12 @@ static int receive_data(int f_in, char *
7b675ff5
WD
51 exit_cleanup(RERR_FILEIO);
52 }
edd5f785 53
67c08134 54+ if (do_fsync && fd != -1 && fsync(fd) != 0) {
7b675ff5 55+ rsyserr(FERROR, errno, "fsync failed on %s",
fe6407b5 56+ full_fname(fname));
edd5f785
WD
57+ exit_cleanup(RERR_FILEIO);
58+ }
59+
7b675ff5 60 sum_end(file_sum1);
edd5f785 61
dc3ae351 62 if (mapbuf)
a7219d20 63--- orig/t_stub.c 2005-01-25 12:14:14
01c39596
WD
64+++ t_stub.c 2004-10-09 04:03:09
65@@ -28,6 +28,7 @@
66
67 int modify_window = 0;
68 int module_id = -1;
69+int do_fsync;
70 char *partial_dir;
4f9b6a01 71 struct filter_list_struct server_filter_list;
01c39596 72
a7219d20 73--- orig/util.c 2005-01-28 19:08:20
13bed3dd 74+++ util.c 2004-07-03 20:18:13
afbebe13 75@@ -33,6 +33,7 @@ extern int module_id;
7b675ff5 76 extern int modify_window;
afbebe13 77 extern char *partial_dir;
4f9b6a01 78 extern struct filter_list_struct server_filter_list;
edd5f785
WD
79+extern int do_fsync;
80
81 int sanitize_paths = 0;
82
afbebe13 83@@ -298,6 +299,12 @@ int copy_file(char *source, char *dest,
7b675ff5
WD
84 return -1;
85 }
edd5f785 86
7b675ff5
WD
87+ if (do_fsync && fsync(ofd) < 0) {
88+ rsyserr(FERROR, errno, "fsync failed on %s",
fe6407b5 89+ full_fname(dest));
edd5f785
WD
90+ return -1;
91+ }
92+
7b675ff5
WD
93 return 0;
94 }
95