Debian Codegraph @

internal/rsyncopts/serveroptions.go

raw symbols SCIP
1 package rsyncopts
2
3 func (o *Options) CommandOptions(path string, paths ...string) []string {
4 return append(o.ServerOptions(), append([]string{".", path}, paths...)...)
5 }
6
7 // rsync/options.c:server_options
8 func (o *Options) ServerOptions() []string {
9 var sargv []string
10
11 // if (blocking_io == -1)
12 // blocking_io = 0;
13
14 sargv = append(sargv, "--server")
15
16 // if (daemon_over_rsh) {
17 // args[ac++] = "--daemon";
18 // *argc = ac;
19 // /* if we're passing --daemon, we're done */
20 // return;
21 // }
22
23 if !o.Sender() {
24 sargv = append(sargv, "--sender")
25 }
26
27 argstr := "-"
28
29 // TODO: support verbosity levels, i.e. one or more -v
30 if o.Verbose() {
31 argstr += "v"
32 }
33
34 // /* the -q option is intentionally left out */
35 // if (make_backups)
36 // argstr[x++] = 'b';
37 if o.UpdateOnly() {
38 argstr += "u"
39 }
40 if o.DryRun() {
41 argstr += "n"
42 }
43 if o.PreserveLinks() {
44 argstr += "l"
45 }
46 // if (copy_links)
47 // argstr[x++] = 'L';
48
49 // if (whole_file > 0)
50 // argstr[x++] = 'W';
51 // /* We don't need to send --no-whole-file, because it's the
52 // * default for remote transfers, and in any case old versions
53 // * of rsync will not understand it. */
54
55 // if (preserve_hard_links)
56 // argstr[x++] = 'H';
57 if o.PreserveUid() {
58 argstr += "o"
59 }
60 if o.PreserveGid() {
61 argstr += "g"
62 }
63 if o.PreserveDevices() {
64 argstr += "D"
65 }
66 if o.PreserveMTimes() {
67 argstr += "t"
68 }
69 if o.PreservePerms() {
70 argstr += "p"
71 }
72 if o.Recurse() {
73 argstr += "r"
74 }
75 if o.AlwaysChecksum() {
76 argstr += "c"
77 }
78 // if (cvs_exclude)
79 // argstr[x++] = 'C';
80 if o.IgnoreTimes() {
81 argstr += "I"
82 }
83 // if (relative_paths)
84 // argstr[x++] = 'R';
85 // if (one_file_system)
86 // argstr[x++] = 'x';
87 // if (sparse_files)
88 // argstr[x++] = 'S';
89 // if (do_compression)
90 // argstr[x++] = 'z';
91
92 // /* this is a complete hack - blame Rusty
93
94 // this is a hack to make the list_only (remote file list)
95 // more useful */
96 // if (list_only && !recurse)
97 // argstr[x++] = 'r';
98
99 // argstr[x] = 0;
100
101 if argstr != "-" {
102 sargv = append(sargv, argstr)
103 }
104
105 if o.Sender() && o.DoFsync() {
106 sargv = append(sargv, "--fsync")
107 }
108
109 // if (block_size) {
110 // if (asprintf(&arg, "-B%u", block_size) < 0)
111 // goto oom;
112 // args[ac++] = arg;
113 // }
114
115 // if (max_delete && am_sender) {
116 // if (asprintf(&arg, "--max-delete=%d", max_delete) < 0)
117 // goto oom;
118 // args[ac++] = arg;
119 // }
120
121 // if (batch_prefix) {
122 // char *r_or_w = write_batch ? "write" : "read";
123 // if (asprintf(&arg, "--%s-batch=%s", r_or_w, batch_prefix) < 0)
124 // goto oom;
125 // args[ac++] = arg;
126 // }
127
128 // if (io_timeout) {
129 // if (asprintf(&arg, "--timeout=%d", io_timeout) < 0)
130 // goto oom;
131 // args[ac++] = arg;
132 // }
133
134 // if (bwlimit) {
135 // if (asprintf(&arg, "--bwlimit=%d", bwlimit) < 0)
136 // goto oom;
137 // args[ac++] = arg;
138 // }
139
140 // if (backup_dir) {
141 // args[ac++] = "--backup-dir";
142 // args[ac++] = backup_dir;
143 // }
144
145 // /* Only send --suffix if it specifies a non-default value. */
146 // if (strcmp(backup_suffix, backup_dir ? "" : BACKUP_SUFFIX) != 0) {
147 // /* We use the following syntax to avoid weirdness with '~'. */
148 // if (asprintf(&arg, "--suffix=%s", backup_suffix) < 0)
149 // goto oom;
150 // args[ac++] = arg;
151 // }
152
153 // if (delete_excluded)
154 // args[ac++] = "--delete-excluded";
155 // else if (delete_mode)
156 // args[ac++] = "--delete";
157
158 // if (size_only)
159 // args[ac++] = "--size-only";
160
161 // if (modify_window_set) {
162 // if (asprintf(&arg, "--modify-window=%d", modify_window) < 0)
163 // goto oom;
164 // args[ac++] = arg;
165 // }
166
167 // if (keep_partial)
168 // args[ac++] = "--partial";
169
170 // if (force_delete)
171 // args[ac++] = "--force";
172
173 // if (delete_after)
174 // args[ac++] = "--delete-after";
175
176 // if (ignore_errors)
177 // args[ac++] = "--ignore-errors";
178
179 // if (copy_unsafe_links)
180 // args[ac++] = "--copy-unsafe-links";
181
182 // if (safe_symlinks)
183 // args[ac++] = "--safe-links";
184
185 // if (numeric_ids)
186 // args[ac++] = "--numeric-ids";
187
188 // if (only_existing && am_sender)
189 // args[ac++] = "--existing";
190
191 // if (opt_ignore_existing && am_sender)
192 // args[ac++] = "--ignore-existing";
193
194 // if (tmpdir) {
195 // args[ac++] = "--temp-dir";
196 // args[ac++] = tmpdir;
197 // }
198
199 // if (compare_dest && am_sender) {
200 // /* the server only needs this option if it is not the sender,
201 // * and it may be an older version that doesn't know this
202 // * option, so don't send it if client is the sender.
203 // */
204 // args[ac++] = link_dest ? "--link-dest" : "--compare-dest";
205 // args[ac++] = compare_dest;
206 // }
207
208 // if (files_from && (!am_sender || remote_filesfrom_file)) {
209 // if (remote_filesfrom_file) {
210 // args[ac++] = "--files-from";
211 // args[ac++] = remote_filesfrom_file;
212 // if (eol_nulls)
213 // args[ac++] = "--from0";
214 // } else {
215 // args[ac++] = "--files-from=-";
216 // args[ac++] = "--from0";
217 // }
218 // }
219
220 return sargv
221 }