Commit | Line | Data |
---|---|---|
edd5f785 WD |
1 | This patch from Sami Farin lets you specify --fsync if you want fsync() |
2 | to be called on every file we write. | |
3 | ||
7f2baf27 | 4 | --- options.c 6 May 2004 21:08:01 -0000 1.148 |
fe6407b5 | 5 | +++ options.c 15 May 2004 20:20:27 -0000 |
edd5f785 WD |
6 | @@ -37,6 +37,7 @@ int make_backups = 0; |
7 | **/ | |
8 | int whole_file = -1; | |
9 | ||
10 | +int do_fsync = 0; | |
11 | int archive_mode = 0; | |
12 | int copy_links = 0; | |
13 | int preserve_links = 0; | |
14 | @@ -230,6 +231,7 @@ void usage(enum logcode F) | |
15 | rprintf(F," -b, --backup make backups (see --suffix & --backup-dir)\n"); | |
16 | rprintf(F," --backup-dir make backups into this directory\n"); | |
17 | rprintf(F," --suffix=SUFFIX backup suffix (default %s w/o --backup-dir)\n",BACKUP_SUFFIX); | |
18 | + rprintf(F," --fsync fsync every written file\n"); | |
19 | rprintf(F," -u, --update update only (don't overwrite newer files)\n"); | |
20 | rprintf(F," -l, --links copy symlinks as symlinks\n"); | |
21 | rprintf(F," -L, --copy-links copy the referent of all symlinks\n"); | |
22 | @@ -332,6 +334,7 @@ static struct poptOption long_options[] | |
23 | {"safe-links", 0, POPT_ARG_NONE, &safe_symlinks, 0, 0, 0 }, | |
24 | {"help", 'h', POPT_ARG_NONE, 0, 'h', 0, 0 }, | |
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 }, | |
30 | @@ -943,6 +946,9 @@ void server_options(char **args,int *arg | |
31 | args[ac++] = "--temp-dir"; | |
32 | args[ac++] = tmpdir; | |
33 | } | |
34 | + | |
35 | + if (do_fsync && am_sender) | |
36 | + args[ac++] = "--fsync"; | |
37 | ||
38 | if (compare_dest && am_sender) { | |
39 | /* the server only needs this option if it is not the sender, | |
fe6407b5 WD |
40 | --- receiver.c 15 May 2004 19:31:10 -0000 1.78 |
41 | +++ receiver.c 15 May 2004 20:20:27 -0000 | |
7f2baf27 | 42 | @@ -46,6 +46,7 @@ extern int module_id; |
edd5f785 WD |
43 | extern int ignore_errors; |
44 | extern int orig_umask; | |
7f2baf27 | 45 | extern int keep_partial; |
edd5f785 WD |
46 | +extern int do_fsync; |
47 | ||
48 | static void delete_one(char *fn, int is_dir) | |
49 | { | |
fe6407b5 | 50 | @@ -266,6 +267,12 @@ static int receive_data(int f_in,struct |
edd5f785 WD |
51 | |
52 | if (fd != -1 && offset > 0 && sparse_end(fd) != 0) { | |
fe6407b5 WD |
53 | rsyserr(FERROR, errno, "write failed on %s", |
54 | + full_fname(fname)); | |
edd5f785 WD |
55 | + exit_cleanup(RERR_FILEIO); |
56 | + } | |
57 | + | |
58 | + if (do_fsync && (fd != -1) && (fsync(fd) != 0)) { | |
fe6407b5 WD |
59 | + rsyserr(FERROR, errno, "fsync failed on %s", |
60 | full_fname(fname)); | |
edd5f785 WD |
61 | exit_cleanup(RERR_FILEIO); |
62 | } | |
fe6407b5 WD |
63 | --- util.c 15 May 2004 19:31:10 -0000 1.143 |
64 | +++ util.c 15 May 2004 20:20:28 -0000 | |
edd5f785 WD |
65 | @@ -29,6 +29,7 @@ |
66 | ||
67 | extern int verbose; | |
68 | extern struct exclude_list_struct server_exclude_list; | |
69 | +extern int do_fsync; | |
70 | ||
71 | int sanitize_paths = 0; | |
72 | ||
fe6407b5 | 73 | @@ -291,6 +292,12 @@ int copy_file(char *source, char *dest, |
edd5f785 WD |
74 | |
75 | if (close(ofd) < 0) { | |
fe6407b5 WD |
76 | rsyserr(FERROR, errno, "close failed on %s", |
77 | + full_fname(dest)); | |
edd5f785 WD |
78 | + return -1; |
79 | + } | |
80 | + | |
81 | + if (do_fsync && fsync(ofd) < 0) { | |
fe6407b5 WD |
82 | + rsyserr(FERROR, errno, "fsync failed on %s", |
83 | full_fname(dest)); | |
edd5f785 WD |
84 | return -1; |
85 | } |