Debian Codegraph @

internal/rsyncopts/rsyncopts.go

raw symbols SCIP
1 // Package rsyncopts implements a parser for command-line options that
2 // implements a subset of popt(3) semantics; just enough to parse typical
3 // rsync(1) invocations without the advanced popt features like aliases
4 // or option prefix matching (not --del, only --delete).
5 //
6 // If we encounter arguments that rsync(1) parses differently compared to this
7 // package, then this package should be adjusted to match rsync(1).
8 package rsyncopts
9
10 import (
11 "errors"
12 "fmt"
13 "math"
14 "os"
15 "slices"
16 "strconv"
17 "strings"
18 "syscall"
19 "unicode"
20
21 "github.com/gokrazy/rsync/internal/rsyncos"
22 "github.com/gokrazy/rsync/internal/version"
23 )
24
25 const (
26 OPT_SERVER = 1000 + iota
27 OPT_DAEMON
28 OPT_SENDER
29 OPT_EXCLUDE
30 OPT_EXCLUDE_FROM
31 OPT_FILTER
32 OPT_COMPARE_DEST
33 OPT_COPY_DEST
34 OPT_LINK_DEST
35 OPT_HELP
36 OPT_INCLUDE
37 OPT_INCLUDE_FROM
38 OPT_MODIFY_WINDOW
39 OPT_MIN_SIZE
40 OPT_CHMOD
41 OPT_READ_BATCH
42 OPT_WRITE_BATCH
43 OPT_ONLY_WRITE_BATCH
44 OPT_MAX_SIZE
45 OPT_NO_D
46 OPT_APPEND
47 OPT_NO_ICONV
48 OPT_INFO
49 OPT_DEBUG
50 OPT_BLOCK_SIZE
51 OPT_USERMAP
52 OPT_GROUPMAP
53 OPT_CHOWN
54 OPT_BWLIMIT
55 OPT_STDERR
56 OPT_OLD_COMPRESS
57 OPT_NEW_COMPRESS
58 OPT_NO_COMPRESS
59 OPT_OLD_ARGS
60 OPT_STOP_AFTER
61 OPT_STOP_AT
62 OPT_REFUSED_BASE = 9000
63 )
64
65 type InfoLevel int
66
67 const (
68 INFO_BACKUP InfoLevel = iota
69 INFO_COPY
70 INFO_DEL
71 INFO_FLIST
72 INFO_MISC
73 INFO_MOUNT
74 INFO_NAME
75 INFO_NONREG
76 INFO_PROGRESS
77 INFO_REMOVE
78 INFO_SKIP
79 INFO_STATS
80 INFO_SYMSAFE
81 COUNT_INFO
82 )
83
84 type DebugLevel int
85
86 const (
87 DEBUG_ACL DebugLevel = iota
88 DEBUG_BACKUP
89 DEBUG_BIND
90 DEBUG_CHDIR
91 DEBUG_CONNECT
92 DEBUG_CMD
93 DEBUG_DEL
94 DEBUG_DELTASUM
95 DEBUG_DUP
96 DEBUG_EXIT
97 DEBUG_FILTER
98 DEBUG_FLIST
99 DEBUG_FUZZY
100 DEBUG_GENR
101 DEBUG_HASH
102 DEBUG_HLINK
103 DEBUG_ICONV
104 DEBUG_IO
105 DEBUG_NSTR
106 DEBUG_OWN
107 DEBUG_PROTO
108 DEBUG_RECV
109 DEBUG_SEND
110 DEBUG_TIME
111 COUNT_DEBUG
112 )
113
114 var tridgeDefaults = Options{
115 msgs2stderr: 2, // Default: send errors to stderr for local & remote-shell transfers
116 output_motd: 1,
117 human_readable: 1,
118 allow_inc_recurse: 1,
119 xfer_dirs: -1,
120 relative_paths: -1,
121 implied_dirs: 1,
122 max_delete: math.MinInt32,
123 whole_file: -1,
124 do_compression_level: math.MinInt32,
125 rsync_path: "rsync",
126 default_af_hint: syscall.AF_INET6,
127 blocking_io: -1,
128 protocol_version: 27,
129 }
130
131 // NewOptions returns an Options struct with all options initialized to their
132 // default values. Note that ParseArguments will set some options (that default
133 // to -1) based on the encountered command-line flags and built-in rules.
134 func NewOptions(osenv *rsyncos.Env) *Options {
135 opts := tridgeDefaults // copy
136 opts.osenv = osenv
137 opts.table = func() []poptOption {
138 return opts.tridgeTable()
139 }
140 return &opts
141 }
142
143 var gokrazyDefaults = Options{
144 msgs2stderr: 2, // Default: send errors to stderr for local & remote-shell transfers
145 output_motd: 1,
146 human_readable: 1,
147 // TODO: if/when allow_inc_recurse gets implemented,
148 // default to 1 to match tridge rsync
149 allow_inc_recurse: 0,
150 xfer_dirs: -1,
151 relative_paths: -1,
152 implied_dirs: 1,
153 max_delete: math.MinInt32,
154 whole_file: -1,
155 do_compression_level: math.MinInt32,
156 rsync_path: "rsync",
157 default_af_hint: syscall.AF_INET6,
158 blocking_io: -1,
159 protocol_version: 27,
160 }
161
162 // NewOptions returns an Options struct with all options initialized to their
163 // default values. Note that ParseArguments will set some options (that default
164 // to -1) based on the encountered command-line flags and built-in rules.
165 func NewOptionsWithGokrazyDefaults(osenv *rsyncos.Env) *Options {
166 opts := gokrazyDefaults // copy
167 opts.osenv = osenv
168 opts.table = func() []poptOption {
169 return opts.gokrazyTable()
170 }
171 return &opts
172 }
173
174 // GokrazyClientOptions contains additional command-line flags, prefixed with
175 // gokr. (like --gokr.dont_restrict) to not clash with rsync flag names.
176 type GokrazyClientOptions struct {
177 DontRestrict int
178 }
179
180 func (o *GokrazyClientOptions) table() []poptOption {
181 return []poptOption{
182 /* longName, shortName, argInfo, arg, val */
183 {"gokr.dont_restrict", "", POPT_ARG_NONE, &o.DontRestrict, 0},
184 }
185 }
186
187 // GokrazyDaemonOptions contains additional command-line flags, prefixed with
188 // gokr. (like --gokr.modulemap) to not clash with rsync flag names.
189 type GokrazyDaemonOptions struct {
190 Config string
191 Listen string
192 MonitoringListen string
193 AnonSSHListen string
194 ModuleMap string
195 }
196
197 func (o *GokrazyDaemonOptions) table() []poptOption {
198 return []poptOption{
199 /* longName, shortName, argInfo, arg, val */
200 {"gokr.config", "", POPT_ARG_STRING, &o.Config, 0},
201 {"gokr.listen", "", POPT_ARG_STRING, &o.Listen, 0},
202 {"gokr.monitoring_listen", "", POPT_ARG_STRING, &o.MonitoringListen, 0},
203 {"gokr.anonssh_listen", "", POPT_ARG_STRING, &o.AnonSSHListen, 0},
204 {"gokr.modulemap", "", POPT_ARG_STRING, &o.ModuleMap, 0},
205 }
206 }
207
208 type Options struct {
209 osenv *rsyncos.Env
210 table func() []poptOption
211
212 GokrazyClient GokrazyClientOptions
213 GokrazyDaemon GokrazyDaemonOptions
214
215 // not directly referenced in the table, but used in the special case code.
216 do_compression int
217 info [COUNT_INFO]uint16
218 debug [COUNT_DEBUG]uint16
219 local_server int
220 filterRules []string
221
222 // order matches long_options order
223 verbose int
224 msgs2stderr int
225 quiet int
226 output_motd int
227 do_stats int
228 human_readable int
229 dry_run int
230 recurse int
231 allow_inc_recurse int
232 xfer_dirs int
233 preserve_perms int
234 preserve_executability int
235 preserve_acls int
236 preserve_xattrs int
237 preserve_mtimes int
238 preserve_atimes int
239 open_noatime int
240 preserve_crtimes int
241 omit_dir_times int
242 omit_link_times int
243 modify_window int
244 am_root int // 0 = normal, 1 = root, 2 = --super, -1 = --fake-super
245 preserve_uid int
246 preserve_gid int
247 preserve_devices int
248 copy_devices int
249 write_devices int
250 preserve_specials int
251 preserve_links int
252 copy_links int
253 copy_unsafe_links int
254 safe_symlinks int
255 munge_symlinks int
256 copy_dirlinks int
257 keep_dirlinks int
258 preserve_hard_links int
259 relative_paths int
260 implied_dirs int
261 ignore_times int
262 size_only int
263 one_file_system int
264 update_only int
265 ignore_non_existing int
266 ignore_existing int
267 max_size_arg string
268 min_size_arg string
269 max_alloc_arg string
270 sparse_files int
271 preallocate_files int
272 inplace int
273 append_mode int
274 delete_during int
275 delete_mode int
276 delete_before int
277 delete_after int
278 delete_excluded int
279 missing_args int // 0 = FERROR_XFER, 1 = ignore, 2 = delete
280 remove_source_files int
281 force_delete int
282 ignore_errors int
283 max_delete int
284 cvs_exclude int
285 // If 1, send the whole file as literal data rather than trying to create an
286 // incremental diff.
287 // If -1, then look at whether we're local or remote and go by that.
288 // See also disable_deltas_p()
289 whole_file int
290 always_checksum int
291 checksum_choice string
292 fuzzy_basis int
293 compress_choice string
294 skip_compress string
295 do_compression_level int
296 do_progress int
297 keep_partial int
298 partial_dir string
299 delay_updates int
300 prune_empty_dirs int
301 logfile_name string
302 logfile_format string
303 stdout_format string
304 itemize_changes int
305 bwlimit_arg string
306 bwlimit int
307 make_backups int
308 backup_dir string
309 backup_suffix string
310 list_only int
311 batch_name string
312 files_from string
313 eol_nulls int
314 old_style_args int // intentionally set to 0; unsupported
315 protect_args int // intentionally set to 0; currently unsupported
316 trust_sender int
317 numeric_ids int
318 io_timeout int
319 connect_timeout int
320 do_fsync int
321 shell_cmd string
322 rsync_path string
323 tmpdir string
324 iconv_opt string
325 default_af_hint int
326 allow_8bit_chars int
327 mkpath_dest_arg int
328 use_qsort int
329 copy_as string
330 bind_address string // numeric IPv4 or IPv6, or a hostname
331 rsync_port int
332 sockopts string
333 password_file string
334 early_input_file string
335 blocking_io int
336 outbuf_mode string
337 protocol_version int
338 checksum_seed int
339 am_server int
340 am_sender int
341 am_daemon int
342
343 daemon_bwlimit int
344 config_file string
345 daemon_opt int
346 no_detach int
347 }
348
349 type priority int
350
351 const (
352 DEFAULT_PRIORITY priority = iota
353 HELP_PRIORITY
354 USER_PRIORITY
355 LIMIT_PRIORITY
356 )
357
358 const (
359 W_CLI = 1 << iota
360 W_SRV
361 W_SND
362 W_REC
363 )
364
365 type output struct {
366 name string
367 where int
368 help string
369 }
370
371 var infoWords = [...]output{
372 {"BACKUP", W_REC, "Mention files backed up"},
373 {"COPY", W_REC, "Mention files copied locally on the receiving side"},
374 {"DEL", W_REC, "Mention deletions on the receiving side"},
375 {"FLIST", W_CLI, "Mention file-list receiving/sending (levels 1-2)"},
376 {"MISC", W_SND | W_REC, "Mention miscellaneous information (levels 1-2)"},
377 {"MOUNT", W_SND | W_REC, "Mention mounts that were found or skipped"},
378 {"NAME", W_SND | W_REC, "Mention 1) updated file/dir names, 2) unchanged names"},
379 {"NONREG", W_REC, "Mention skipped non-regular files (default 1, 0 disables)"},
380 {"PROGRESS", W_CLI, "Mention 1) per-file progress or 2) total transfer progress"},
381 {"REMOVE", W_SND, "Mention files removed on the sending side"},
382 {"SKIP", W_REC, "Mention files skipped due to transfer overrides (levels 1-2)"},
383 {"STATS", W_CLI | W_SRV, "Mention statistics at end of run (levels 1-3)"},
384 {"SYMSAFE", W_SND | W_REC, "Mention symlinks that are unsafe"},
385 }
386
387 var debugWords = [...]output{
388 {"ACL", W_SND | W_REC, "Debug extra ACL info"},
389 {"BACKUP", W_REC, "Debug backup actions (levels 1-2)"},
390 {"CHDIR", W_CLI | W_SRV, "Debug when the current directory changes"},
391 {"BIND", W_CLI, "Debug socket bind actions"},
392 {"CONNECT", W_CLI, "Debug connection events (levels 1-2)"},
393 {"CMD", W_CLI, "Debug commands+options that are issued (levels 1-2)"},
394 {"DEL", W_REC, "Debug delete actions (levels 1-3)"},
395 {"DELTASUM", W_SND | W_REC, "Debug delta-transfer checksumming (levels 1-4)"},
396 {"DUP", W_REC, "Debug weeding of duplicate names"},
397 {"EXIT", W_CLI | W_SRV, "Debug exit events (levels 1-3)"},
398 {"FILTER", W_SND | W_REC, "Debug filter actions (levels 1-3)"},
399 {"FLIST", W_SND | W_REC, "Debug file-list operations (levels 1-4)"},
400 {"FUZZY", W_REC, "Debug fuzzy scoring (levels 1-2)"},
401 {"GENR", W_REC, "Debug generator functions"},
402 {"HASH", W_SND | W_REC, "Debug hashtable code"},
403 {"HLINK", W_SND | W_REC, "Debug hard-link actions (levels 1-3)"},
404 {"ICONV", W_CLI | W_SRV, "Debug iconv character conversions (levels 1-2)"},
405 {"IO", W_CLI | W_SRV, "Debug I/O routines (levels 1-4)"},
406 {"NSTR", W_CLI | W_SRV, "Debug negotiation strings"},
407 {"OWN", W_REC, "Debug ownership changes in users & groups (levels 1-2)"},
408 {"PROTO", W_CLI | W_SRV, "Debug protocol information"},
409 {"RECV", W_REC, "Debug receiver functions"},
410 {"SEND", W_SND, "Debug sender functions"},
411 {"TIME", W_REC, "Debug setting of modified times (levels 1-2)"},
412 }
413
414 func parseOutputWords(osenv *rsyncos.Env, words []output, levels []uint16, str string, prio priority) error {
415 Level:
416 for s := range strings.SplitSeq(str, ",") {
417 if strings.TrimSpace(s) == "" {
418 continue
419 }
420 trimmed := strings.TrimRightFunc(s, unicode.IsNumber)
421 lev := 1
422 if len(trimmed) < len(s) {
423 var err error
424 lev, err = strconv.Atoi(s[len(trimmed):])
425 if err != nil {
426 return err
427 }
428 }
429 trimmed = strings.ToLower(trimmed)
430 all := false
431 switch trimmed {
432 case "help":
433 osenv.Logf("TODO: print --info/--debug help and exit")
434 os.Exit(0)
435 case "none":
436 lev = 0
437 case "all":
438 all = true
439 }
440 for j := range words {
441 word := words[j]
442 if strings.ToLower(word.name) == trimmed || all {
443 levels[j] = uint16(lev)
444 if !all {
445 continue Level
446 }
447 }
448 }
449 if !all {
450 return fmt.Errorf("unknown --info/--debug item: %q", trimmed)
451 }
452 }
453 return nil
454 }
455
456 func (o *Options) setOutputVerbosity(prio priority) error {
457 debugVerbosity := [...]string{
458 "",
459 "",
460 "BIND,CMD,CONNECT,DEL,DELTASUM,DUP,FILTER,FLIST,ICONV",
461 "ACL,BACKUP,CONNECT2,DELTASUM2,DEL2,EXIT,FILTER2,FLIST2,FUZZY,GENR,OWN,RECV,SEND,TIME",
462 "CMD2,DELTASUM3,DEL3,EXIT2,FLIST3,ICONV2,OWN2,PROTO,TIME2",
463 "CHDIR,DELTASUM4,FLIST4,FUZZY2,HASH,HLINK",
464 }
465 infoVerbosity := [...]string{
466 "NONREG",
467 "COPY,DEL,FLIST,MISC,NAME,STATS,SYMSAFE",
468 "BACKUP,MISC2,MOUNT,NAME2,REMOVE,SKIP",
469 }
470 for j := 0; j <= o.verbose; j++ {
471 if j < len(infoVerbosity) {
472 if err := parseOutputWords(o.osenv, infoWords[:], o.info[:], infoVerbosity[j], prio); err != nil {
473 return err
474 }
475 }
476 if j < len(debugVerbosity) {
477 if err := parseOutputWords(o.osenv, debugWords[:], o.debug[:], debugVerbosity[j], prio); err != nil {
478 return err
479 }
480 }
481 }
482 return nil
483 }
484
485 func (o *Options) DaemonHelp() string {
486 return version.Read() + `
487 gokrazy/rsync is a native Go rsync implementation.
488 It recognizes all command-line flags that the original rsync supports,
489 but might not implement all functionality (and instead error out).
490
491 See the rsync(1) man page for more details on rsync.
492 For your convenience, here is the rsync --daemon --help output:
493
494 --daemon run as an rsync daemon
495 --address=ADDRESS bind to the specified address
496 --bwlimit=RATE limit socket I/O bandwidth
497 --config=FILE specify alternate rsyncd.conf file
498 --dparam=OVERRIDE, -M override global daemon config parameter
499 --no-detach do not detach from the parent
500 --port=PORT listen on alternate port number
501 --log-file=FILE override the "log file" setting
502 --log-file-format=FMT override the "log format" setting
503 --sockopts=OPTIONS specify custom TCP options
504 --verbose, -v increase verbosity
505 --ipv4, -4 prefer IPv4
506 --ipv6, -6 prefer IPv6
507 --help, -h show this help (when used with --daemon)
508
509 In addition, the following gokrazy-specific flags are supported:
510
511 --gokr.config path to a config file (if unspecified,
512 os.UserConfigDir()/gokr-rsyncd.toml is used)
513 --gokr.listen [host]:port listen address for the rsync daemon protocol
514 --gokr.monitoring_listen optional [host]:port listen address for a HTTP debug interface
515 --gokr.anonssh_listen optional [host]:port listen address for
516 the rsync daemon protocol via anonymous SSH
517 --gokr.modulemap <modulename>=<path> pairs for quick setup of the server,
518 without a config file
519
520 See https://github.com/gokrazy/rsync for updates, bug reports, and answers
521 `
522 }
523
524 func (o *Options) Help() string {
525 return version.Read() + `
526
527 gokrazy/rsync is a native Go rsync implementation.
528 It recognizes all command-line flags that the original rsync supports,
529 but might not implement all functionality (and instead error out).
530
531 See the rsync(1) man page for more details on rsync.
532 For your convenience, here is the rsync --help output:
533
534 rsync is a file transfer program capable of efficient remote update
535 via a fast differencing algorithm.
536
537 Usage: rsync [OPTION]... SRC [SRC]... DEST
538 or rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST
539 or rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST
540 or rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST
541 or rsync [OPTION]... [USER@]HOST:SRC [DEST]
542 or rsync [OPTION]... [USER@]HOST::SRC [DEST]
543 or rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]
544 The ':' usages connect via remote shell, while '::' & 'rsync://' usages connect
545 to an rsync daemon, and require SRC or DEST to start with a module name.
546
547 Options:
548
549 --verbose, -v increase verbosity
550 --info=FLAGS fine-grained informational verbosity
551 --debug=FLAGS fine-grained debug verbosity
552 --stderr=e|a|c change stderr output mode (default: errors)
553 --quiet, -q suppress non-error messages
554 --no-motd suppress daemon-mode MOTD
555 --checksum, -c skip based on checksum, not mod-time & size
556 --archive, -a archive mode is -rlptgoD (no -A,-X,-U,-N,-H)
557 --no-OPTION turn off an implied OPTION (e.g. --no-D)
558 --recursive, -r recurse into directories
559 --relative, -R use relative path names
560 --no-implied-dirs don't send implied dirs with --relative
561 --backup, -b make backups (see --suffix & --backup-dir)
562 --backup-dir=DIR make backups into hierarchy based in DIR
563 --suffix=SUFFIX backup suffix (default ~ w/o --backup-dir)
564 --update, -u skip files that are newer on the receiver
565 --inplace update destination files in-place
566 --append append data onto shorter files
567 --append-verify --append w/old data in file checksum
568 --dirs, -d transfer directories without recursing
569 --old-dirs, --old-d works like --dirs when talking to old rsync
570 --mkpath create destination's missing path components
571 --links, -l copy symlinks as symlinks
572 --copy-links, -L transform symlink into referent file/dir
573 --copy-unsafe-links only "unsafe" symlinks are transformed
574 --safe-links ignore symlinks that point outside the tree
575 --munge-links munge symlinks to make them safe & unusable
576 --copy-dirlinks, -k transform symlink to dir into referent dir
577 --keep-dirlinks, -K treat symlinked dir on receiver as dir
578 --hard-links, -H preserve hard links
579 --perms, -p preserve permissions
580 --executability, -E preserve executability
581 --chmod=CHMOD affect file and/or directory permissions
582 --acls, -A preserve ACLs (implies --perms)
583 --xattrs, -X preserve extended attributes
584 --owner, -o preserve owner (super-user only)
585 --group, -g preserve group
586 --devices preserve device files (super-user only)
587 --copy-devices copy device contents as a regular file
588 --write-devices write to devices as files (implies --inplace)
589 --specials preserve special files
590 -D same as --devices --specials
591 --times, -t preserve modification times
592 --atimes, -U preserve access (use) times
593 --open-noatime avoid changing the atime on opened files
594 --crtimes, -N preserve create times (newness)
595 --omit-dir-times, -O omit directories from --times
596 --omit-link-times, -J omit symlinks from --times
597 --super receiver attempts super-user activities
598 --fake-super store/recover privileged attrs using xattrs
599 --sparse, -S turn sequences of nulls into sparse blocks
600 --preallocate allocate dest files before writing them
601 --dry-run, -n perform a trial run with no changes made
602 --whole-file, -W copy files whole (w/o delta-xfer algorithm)
603 --checksum-choice=STR choose the checksum algorithm (aka --cc)
604 --one-file-system, -x don't cross filesystem boundaries
605 --block-size=SIZE, -B force a fixed checksum block-size
606 --rsh=COMMAND, -e specify the remote shell to use
607 --rsync-path=PROGRAM specify the rsync to run on remote machine
608 --existing skip creating new files on receiver
609 --ignore-existing skip updating files that exist on receiver
610 --remove-source-files sender removes synchronized files (non-dir)
611 --del an alias for --delete-during
612 --delete delete extraneous files from dest dirs
613 --delete-before receiver deletes before xfer, not during
614 --delete-during receiver deletes during the transfer
615 --delete-delay find deletions during, delete after
616 --delete-after receiver deletes after transfer, not during
617 --delete-excluded also delete excluded files from dest dirs
618 --ignore-missing-args ignore missing source args without error
619 --delete-missing-args delete missing source args from destination
620 --ignore-errors delete even if there are I/O errors
621 --force force deletion of dirs even if not empty
622 --max-delete=NUM don't delete more than NUM files
623 --max-size=SIZE don't transfer any file larger than SIZE
624 --min-size=SIZE don't transfer any file smaller than SIZE
625 --max-alloc=SIZE change a limit relating to memory alloc
626 --partial keep partially transferred files
627 --partial-dir=DIR put a partially transferred file into DIR
628 --delay-updates put all updated files into place at end
629 --prune-empty-dirs, -m prune empty directory chains from file-list
630 --numeric-ids don't map uid/gid values by user/group name
631 --usermap=STRING custom username mapping
632 --groupmap=STRING custom groupname mapping
633 --chown=USER:GROUP simple username/groupname mapping
634 --timeout=SECONDS set I/O timeout in seconds
635 --contimeout=SECONDS set daemon connection timeout in seconds
636 --ignore-times, -I don't skip files that match size and time
637 --size-only skip files that match in size
638 --modify-window=NUM, -@ set the accuracy for mod-time comparisons
639 --temp-dir=DIR, -T create temporary files in directory DIR
640 --fuzzy, -y find similar file for basis if no dest file
641 --compare-dest=DIR also compare destination files relative to DIR
642 --copy-dest=DIR ... and include copies of unchanged files
643 --link-dest=DIR hardlink to files in DIR when unchanged
644 --compress, -z compress file data during the transfer
645 --compress-choice=STR choose the compression algorithm (aka --zc)
646 --compress-level=NUM explicitly set compression level (aka --zl)
647 --skip-compress=LIST skip compressing files with suffix in LIST
648 --cvs-exclude, -C auto-ignore files in the same way CVS does
649 --filter=RULE, -f add a file-filtering RULE
650 -F same as --filter='dir-merge /.rsync-filter'
651 repeated: --filter='- .rsync-filter'
652 --exclude=PATTERN exclude files matching PATTERN
653 --exclude-from=FILE read exclude patterns from FILE
654 --include=PATTERN don't exclude files matching PATTERN
655 --include-from=FILE read include patterns from FILE
656 --files-from=FILE read list of source-file names from FILE
657 --from0, -0 all *-from/filter files are delimited by 0s
658 --old-args disable the modern arg-protection idiom
659 --secluded-args, -s use the protocol to safely send the args
660 --trust-sender trust the remote sender's file list
661 --copy-as=USER[:GROUP] specify user & optional group for the copy
662 --address=ADDRESS bind address for outgoing socket to daemon
663 --port=PORT specify double-colon alternate port number
664 --sockopts=OPTIONS specify custom TCP options
665 --blocking-io use blocking I/O for the remote shell
666 --outbuf=N|L|B set out buffering to None, Line, or Block
667 --stats give some file-transfer stats
668 --8-bit-output, -8 leave high-bit chars unescaped in output
669 --human-readable, -h output numbers in a human-readable format
670 --progress show progress during transfer
671 -P same as --partial --progress
672 --itemize-changes, -i output a change-summary for all updates
673 --remote-option=OPT, -M send OPTION to the remote side only
674 --out-format=FORMAT output updates using the specified FORMAT
675 --log-file=FILE log what we're doing to the specified FILE
676 --log-file-format=FMT log updates using the specified FMT
677 --password-file=FILE read daemon-access password from FILE
678 --early-input=FILE use FILE for daemon's early exec input
679 --list-only list the files instead of copying them
680 --bwlimit=RATE limit socket I/O bandwidth
681 --stop-after=MINS Stop rsync after MINS minutes have elapsed
682 --stop-at=y-m-dTh:m Stop rsync at the specified point in time
683 --fsync fsync every written file
684 --write-batch=FILE write a batched update to FILE
685 --only-write-batch=FILE like --write-batch but w/o updating dest
686 --read-batch=FILE read a batched update from FILE
687 --protocol=NUM force an older protocol version to be used
688 --iconv=CONVERT_SPEC request charset conversion of filenames
689 --checksum-seed=NUM set block/file checksum seed (advanced)
690 --ipv4, -4 prefer IPv4
691 --ipv6, -6 prefer IPv6
692 --version, -V print the version + other info and exit
693 --help, -h (*) show this help (* -h is help only on its own)
694
695 Use "rsync --daemon --help" to see the daemon-mode command-line options.
696
697 In addition, the following gokrazy-specific flags are supported:
698
699 --gokr.dont_restrict do not restrict file system access to source/dest
700 where available (e.g. with Landlock on Linux)
701
702 See https://github.com/gokrazy/rsync for updates, bug reports, and answers
703 `
704 }
705
706 func (o *Options) ShellCommand() string { return o.shell_cmd }
707 func (o *Options) UpdateOnly() bool { return o.update_only != 0 }
708 func (o *Options) DryRun() bool { return o.dry_run != 0 }
709 func (o *Options) PreserveLinks() bool { return o.preserve_links != 0 }
710 func (o *Options) PreserveUid() bool { return o.preserve_uid != 0 }
711 func (o *Options) PreserveGid() bool { return o.preserve_gid != 0 }
712 func (o *Options) PreserveDevices() bool { return o.preserve_devices != 0 }
713 func (o *Options) PreserveMTimes() bool { return o.preserve_mtimes != 0 }
714 func (o *Options) PreservePerms() bool { return o.preserve_perms != 0 }
715 func (o *Options) PreserveSpecials() bool { return o.preserve_specials != 0 }
716 func (o *Options) PreserveHardLinks() bool { return o.preserve_hard_links != 0 }
717 func (o *Options) DoFsync() bool { return o.do_fsync != 0 }
718 func (o *Options) Recurse() bool { return o.recurse != 0 }
719 func (o *Options) Verbose() bool { return o.verbose != 0 }
720 func (o *Options) DeleteMode() bool { return o.delete_mode != 0 }
721 func (o *Options) Sender() bool { return o.am_sender != 0 }
722 func (o *Options) SetSender() { o.am_sender = 1 }
723 func (o *Options) LocalServer() bool { return o.local_server != 0 }
724 func (o *Options) SetLocalServer() { o.local_server = 1 }
725 func (o *Options) Server() bool { return o.am_server != 0 }
726 func (o *Options) Daemon() bool { return o.am_daemon != 0 }
727 func (o *Options) ConnectTimeoutSeconds() int { return o.connect_timeout }
728 func (o *Options) AlwaysChecksum() bool { return o.always_checksum != 0 }
729 func (o *Options) IgnoreTimes() bool { return o.ignore_times != 0 }
730 func (o *Options) OutputMOTD() bool { return o.output_motd != 0 }
731 func (o *Options) RsyncPort() int { return o.rsync_port }
732 func (o *Options) XferDirs() int { return o.xfer_dirs }
733 func (o *Options) FilterRules() []string { return o.filterRules }
734 func (o *Options) Progress() bool {
735 return o.info[INFO_PROGRESS] > 0
736 }
737
738 func (o *Options) InfoGTE(flag InfoLevel, lvl uint16) bool {
739 return o.info[int(flag)] >= lvl
740 }
741
742 func (o *Options) InfoEQ(flag InfoLevel, lvl uint16) bool {
743 return o.info[int(flag)] == lvl
744 }
745
746 func (o *Options) DebugGTE(flag DebugLevel, lvl uint16) bool {
747 return o.debug[int(flag)] >= lvl
748 }
749
750 func (o *Options) DebugEQ(flag DebugLevel, lvl uint16) bool {
751 return o.debug[int(flag)] == lvl
752 }
753
754 func (o *Options) daemonTable() []poptOption {
755 return []poptOption{
756 /* longName, shortName, argInfo, arg, val */
757 {"address", "", POPT_ARG_STRING, &o.bind_address, 0},
758 {"bwlimit", "", POPT_ARG_INT, &o.daemon_bwlimit, 0},
759 {"config", "", POPT_ARG_STRING, &o.config_file, 0},
760 {"daemon", "", POPT_ARG_NONE, &o.daemon_opt, 0},
761 {"dparam", "M", POPT_ARG_STRING, nil, 'M'},
762 {"ipv4", "4", POPT_ARG_VAL, &o.default_af_hint, syscall.AF_INET},
763 {"ipv6", "6", POPT_ARG_VAL, &o.default_af_hint, syscall.AF_INET6},
764 {"detach", "", POPT_ARG_VAL, &o.no_detach, 0},
765 {"no-detach", "", POPT_ARG_VAL, &o.no_detach, 1},
766 {"log-file", "", POPT_ARG_STRING, &o.logfile_name, 0},
767 {"log-file-format", "", POPT_ARG_STRING, &o.logfile_format, 0},
768 {"port", "", POPT_ARG_INT, &o.rsync_port, 0},
769 {"sockopts", "", POPT_ARG_STRING, &o.sockopts, 0},
770 {"protocol", "", POPT_ARG_INT, &o.protocol_version, 0},
771 {"server", "", POPT_ARG_NONE, &o.am_server, 0},
772 {"temp-dir", "T", POPT_ARG_STRING, &o.tmpdir, 0},
773 {"verbose", "v", POPT_ARG_NONE, nil, 'v'},
774 {"no-verbose", "", POPT_ARG_VAL, &o.verbose, 0},
775 {"no-v", "", POPT_ARG_VAL, &o.verbose, 0},
776 {"help", "h", POPT_ARG_NONE, nil, 'h'},
777 }
778 }
779
780 func (o *Options) gokrazyTable() []poptOption {
781 // Commented out options are not yet implemented.
782 return []poptOption{
783 /* longName, shortName, argInfo, arg, val */
784 {"help", "", POPT_ARG_NONE, nil, OPT_HELP},
785 {"version", "V", POPT_ARG_NONE, nil, 'V'},
786 {"verbose", "v", POPT_ARG_NONE, nil, 'v'},
787 {"no-verbose", "", POPT_ARG_VAL, &o.verbose, 0},
788 {"no-v", "", POPT_ARG_VAL, &o.verbose, 0},
789 {"info", "", POPT_ARG_STRING, nil, OPT_INFO},
790 {"debug", "", POPT_ARG_STRING, nil, OPT_DEBUG},
791 //{"stderr", "", POPT_ARG_STRING, nil, OPT_STDERR},
792 //{"msgs2stderr", "", POPT_ARG_VAL, &o.msgs2stderr, 1},
793 //{"no-msgs2stderr", "", POPT_ARG_VAL, &o.msgs2stderr, 0},
794 //{"quiet", "q", POPT_ARG_NONE, nil, 'q'},
795 {"motd", "", POPT_ARG_VAL, &o.output_motd, 1},
796 {"no-motd", "", POPT_ARG_VAL, &o.output_motd, 0},
797 //{"stats", "", POPT_ARG_NONE, &o.do_stats, 0},
798 //{"human-readable", "h", POPT_ARG_NONE, nil, 'h'},
799 //{"no-human-readable", "", POPT_ARG_VAL, &o.human_readable, 0},
800 //{"no-h", "", POPT_ARG_VAL, &o.human_readable, 0},
801 {"dry-run", "n", POPT_ARG_NONE, &o.dry_run, 0},
802 {"archive", "a", POPT_ARG_NONE, nil, 'a'},
803 {"recursive", "r", POPT_ARG_VAL, &o.recurse, 2},
804 {"no-recursive", "", POPT_ARG_VAL, &o.recurse, 0},
805 {"no-r", "", POPT_ARG_VAL, &o.recurse, 0},
806 //{"inc-recursive", "", POPT_ARG_VAL, &o.allow_inc_recurse, 1},
807 //{"no-inc-recursive", "", POPT_ARG_VAL, &o.allow_inc_recurse, 0},
808 //{"i-r", "", POPT_ARG_VAL, &o.allow_inc_recurse, 1},
809 //{"no-i-r", "", POPT_ARG_VAL, &o.allow_inc_recurse, 0},
810 {"dirs", "d", POPT_ARG_VAL, &o.xfer_dirs, 2},
811 {"no-dirs", "", POPT_ARG_VAL, &o.xfer_dirs, 0},
812 {"no-d", "", POPT_ARG_VAL, &o.xfer_dirs, 0},
813 //{"old-dirs", "", POPT_ARG_VAL, &o.xfer_dirs, 4},
814 //{"old-d", "", POPT_ARG_VAL, &o.xfer_dirs, 4},
815 {"perms", "p", POPT_ARG_VAL, &o.preserve_perms, 1},
816 {"no-perms", "", POPT_ARG_VAL, &o.preserve_perms, 0},
817 {"no-p", "", POPT_ARG_VAL, &o.preserve_perms, 0},
818 //{"executability", "E", POPT_ARG_NONE, &o.preserve_executability, 0},
819 //{"acls", "A", POPT_ARG_NONE, nil, 'A'},
820 //{"no-acls", "", POPT_ARG_VAL, &o.preserve_acls, 0},
821 //{"no-A", "", POPT_ARG_VAL, &o.preserve_acls, 0},
822 //{"xattrs", "X", POPT_ARG_NONE, nil, 'X'},
823 //{"no-xattrs", "", POPT_ARG_VAL, &o.preserve_xattrs, 0},
824 //{"no-X", "", POPT_ARG_VAL, &o.preserve_xattrs, 0},
825 {"times", "t", POPT_ARG_VAL, &o.preserve_mtimes, 1},
826 {"no-times", "", POPT_ARG_VAL, &o.preserve_mtimes, 0},
827 {"no-t", "", POPT_ARG_VAL, &o.preserve_mtimes, 0},
828 //{"atimes", "U", POPT_ARG_NONE, nil, 'U'},
829 //{"no-atimes", "", POPT_ARG_VAL, &o.preserve_atimes, 0},
830 //{"no-U", "", POPT_ARG_VAL, &o.preserve_atimes, 0},
831 //{"open-noatime", "", POPT_ARG_VAL, &o.open_noatime, 1},
832 //{"no-open-noatime", "", POPT_ARG_VAL, &o.open_noatime, 0},
833 //{"crtimes", "N", POPT_ARG_NONE, &o.preserve_crtimes, 1}, // refused
834 //{"no-crtimes", "", POPT_ARG_VAL, &o.preserve_crtimes, 0},
835 //{"no-N", "", POPT_ARG_VAL, &o.preserve_crtimes, 0},
836 //{"omit-dir-times", "O", POPT_ARG_VAL, &o.omit_dir_times, 1},
837 //{"no-omit-dir-times", "", POPT_ARG_VAL, &o.omit_dir_times, 0},
838 //{"no-O", "", POPT_ARG_VAL, &o.omit_dir_times, 0},
839 //{"omit-link-times", "J", POPT_ARG_VAL, &o.omit_link_times, 1},
840 //{"no-omit-link-times", "", POPT_ARG_VAL, &o.omit_link_times, 0},
841 //{"no-J", "", POPT_ARG_VAL, &o.omit_link_times, 0},
842 //{"modify-window", "@", POPT_ARG_INT, &o.modify_window, OPT_MODIFY_WINDOW},
843 //{"super", "", POPT_ARG_VAL, &o.am_root, 2},
844 //{"no-super", "", POPT_ARG_VAL, &o.am_root, 0},
845 //{"fake-super", "", POPT_ARG_VAL, &o.am_root, -1},
846 {"owner", "o", POPT_ARG_VAL, &o.preserve_uid, 1},
847 {"no-owner", "", POPT_ARG_VAL, &o.preserve_uid, 0},
848 {"no-o", "", POPT_ARG_VAL, &o.preserve_uid, 0},
849 {"group", "g", POPT_ARG_VAL, &o.preserve_gid, 1},
850 {"no-group", "", POPT_ARG_VAL, &o.preserve_gid, 0},
851 {"no-g", "", POPT_ARG_VAL, &o.preserve_gid, 0},
852 {"", "D", POPT_ARG_NONE, nil, 'D'},
853 {"no-D", "", POPT_ARG_NONE, nil, OPT_NO_D},
854 {"devices", "", POPT_ARG_VAL, &o.preserve_devices, 1},
855 {"no-devices", "", POPT_ARG_VAL, &o.preserve_devices, 0},
856 //{"copy-devices", "", POPT_ARG_NONE, &o.copy_devices, 0},
857 //{"write-devices", "", POPT_ARG_VAL, &o.write_devices, 1},
858 //{"no-write-devices", "", POPT_ARG_VAL, &o.write_devices, 0},
859 {"specials", "", POPT_ARG_VAL, &o.preserve_specials, 1},
860 {"no-specials", "", POPT_ARG_VAL, &o.preserve_specials, 0},
861 {"links", "l", POPT_ARG_VAL, &o.preserve_links, 1},
862 {"no-links", "", POPT_ARG_VAL, &o.preserve_links, 0},
863 {"no-l", "", POPT_ARG_VAL, &o.preserve_links, 0},
864 //{"copy-links", "L", POPT_ARG_NONE, &o.copy_links, 0},
865 //{"copy-unsafe-links", "", POPT_ARG_NONE, &o.copy_unsafe_links, 0},
866 //{"safe-links", "", POPT_ARG_NONE, &o.safe_symlinks, 0},
867 //{"munge-links", "", POPT_ARG_VAL, &o.munge_symlinks, 1},
868 //{"no-munge-links", "", POPT_ARG_VAL, &o.munge_symlinks, 0},
869 //{"copy-dirlinks", "k", POPT_ARG_NONE, &o.copy_dirlinks, 0},
870 //{"keep-dirlinks", "K", POPT_ARG_NONE, &o.keep_dirlinks, 0},
871 {"hard-links", "H", POPT_ARG_NONE, nil, 'H'},
872 {"no-hard-links", "", POPT_ARG_VAL, &o.preserve_hard_links, 0},
873 {"no-H", "", POPT_ARG_VAL, &o.preserve_hard_links, 0},
874 //{"relative", "R", POPT_ARG_VAL, &o.relative_paths, 1},
875 //{"no-relative", "", POPT_ARG_VAL, &o.relative_paths, 0},
876 //{"no-R", "", POPT_ARG_VAL, &o.relative_paths, 0},
877 //{"implied-dirs", "", POPT_ARG_VAL, &o.implied_dirs, 1},
878 //{"no-implied-dirs", "", POPT_ARG_VAL, &o.implied_dirs, 0},
879 //{"i-d", "", POPT_ARG_VAL, &o.implied_dirs, 1},
880 //{"no-i-d", "", POPT_ARG_VAL, &o.implied_dirs, 0},
881 //{"chmod", "", POPT_ARG_STRING, nil, OPT_CHMOD},
882 {"ignore-times", "I", POPT_ARG_NONE, &o.ignore_times, 0},
883 //{"size-only", "", POPT_ARG_NONE, &o.size_only, 0},
884 //{"one-file-system", "x", POPT_ARG_NONE, nil, 'x'},
885 //{"no-one-file-system", "", POPT_ARG_VAL, &o.one_file_system, 0},
886 //{"no-x", "", POPT_ARG_VAL, &o.one_file_system, 0},
887 {"update", "u", POPT_ARG_NONE, &o.update_only, 0},
888 //{"existing", "", POPT_ARG_NONE, &o.ignore_non_existing, 0},
889 //{"ignore-non-existing", "", POPT_ARG_NONE, &o.ignore_non_existing, 0},
890 //{"ignore-existing", "", POPT_ARG_NONE, &o.ignore_existing, 0},
891 //{"max-size", "", POPT_ARG_STRING, &o.max_size_arg, OPT_MAX_SIZE},
892 //{"min-size", "", POPT_ARG_STRING, &o.min_size_arg, OPT_MIN_SIZE},
893 //{"max-alloc", "", POPT_ARG_STRING, &o.max_alloc_arg, 0},
894 //{"sparse", "S", POPT_ARG_VAL, &o.sparse_files, 1},
895 //{"no-sparse", "", POPT_ARG_VAL, &o.sparse_files, 0},
896 //{"no-S", "", POPT_ARG_VAL, &o.sparse_files, 0},
897 //{"preallocate", "", POPT_ARG_NONE, &o.preallocate_files, 0},
898 //{"inplace", "", POPT_ARG_VAL, &o.inplace, 1},
899 //{"no-inplace", "", POPT_ARG_VAL, &o.inplace, 0},
900 //{"append", "", POPT_ARG_NONE, nil, OPT_APPEND},
901 //{"append-verify", "", POPT_ARG_VAL, &o.append_mode, 2},
902 //{"no-append", "", POPT_ARG_VAL, &o.append_mode, 0},
903 //{"del", "", POPT_ARG_NONE, &o.delete_during, 0},
904 {"delete", "", POPT_ARG_NONE, &o.delete_mode, 0},
905 //{"delete-before", "", POPT_ARG_NONE, &o.delete_before, 0},
906 //{"delete-during", "", POPT_ARG_VAL, &o.delete_during, 1},
907 //{"delete-delay", "", POPT_ARG_VAL, &o.delete_during, 2},
908 //{"delete-after", "", POPT_ARG_NONE, &o.delete_after, 0},
909 //{"delete-excluded", "", POPT_ARG_NONE, &o.delete_excluded, 0},
910 //{"delete-missing-args", "", POPT_BIT_SET, &o.missing_args, 2},
911 //{"ignore-missing-args", "", POPT_BIT_SET, &o.missing_args, 1},
912 //{"remove-sent-files", "", POPT_ARG_VAL, &o.remove_source_files, 2}, /* deprecated */
913 //{"remove-source-files", "", POPT_ARG_VAL, &o.remove_source_files, 1},
914 //{"force", "", POPT_ARG_VAL, &o.force_delete, 1},
915 //{"no-force", "", POPT_ARG_VAL, &o.force_delete, 0},
916 //{"ignore-errors", "", POPT_ARG_VAL, &o.ignore_errors, 1},
917 //{"no-ignore-errors", "", POPT_ARG_VAL, &o.ignore_errors, 0},
918 //{"max-delete", "", POPT_ARG_INT, &o.max_delete, 0},
919 //{"", "F", POPT_ARG_NONE, nil, 'F'},
920 {"filter", "f", POPT_ARG_STRING, nil, OPT_FILTER},
921 {"exclude", "", POPT_ARG_STRING, nil, OPT_EXCLUDE},
922 {"include", "", POPT_ARG_STRING, nil, OPT_INCLUDE},
923 //{"exclude-from", "", POPT_ARG_STRING, nil, OPT_EXCLUDE_FROM},
924 //{"include-from", "", POPT_ARG_STRING, nil, OPT_INCLUDE_FROM},
925 //{"cvs-exclude", "C", POPT_ARG_NONE, &o.cvs_exclude, 0},
926 //{"whole-file", "W", POPT_ARG_VAL, &o.whole_file, 1},
927 //{"no-whole-file", "", POPT_ARG_VAL, &o.whole_file, 0},
928 //{"no-W", "", POPT_ARG_VAL, &o.whole_file, 0},
929 {"checksum", "c", POPT_ARG_VAL, &o.always_checksum, 1},
930 {"no-checksum", "", POPT_ARG_VAL, &o.always_checksum, 0},
931 {"no-c", "", POPT_ARG_VAL, &o.always_checksum, 0},
932 //{"checksum-choice", "", POPT_ARG_STRING, &o.checksum_choice, 0},
933 //{"cc", "", POPT_ARG_STRING, &o.checksum_choice, 0},
934 //{"block-size", "B", POPT_ARG_STRING, nil, OPT_BLOCK_SIZE},
935 //{"compare-dest", "", POPT_ARG_STRING, nil, OPT_COMPARE_DEST},
936 //{"copy-dest", "", POPT_ARG_STRING, nil, OPT_COPY_DEST},
937 //{"link-dest", "", POPT_ARG_STRING, nil, OPT_LINK_DEST},
938 //{"fuzzy", "y", POPT_ARG_NONE, nil, 'y'},
939 //{"no-fuzzy", "", POPT_ARG_VAL, &o.fuzzy_basis, 0},
940 //{"no-y", "", POPT_ARG_VAL, &o.fuzzy_basis, 0},
941
942 // Regarding compression support, see:
943 // https://github.com/gokrazy/rsync/issues/35#issuecomment-2988582190
944 //
945 //{"compress", "z", POPT_ARG_NONE, nil, 'z'},
946 //{"old-compress", "", POPT_ARG_NONE, nil, OPT_OLD_COMPRESS},
947 //{"new-compress", "", POPT_ARG_NONE, nil, OPT_NEW_COMPRESS},
948 //{"no-compress", "", POPT_ARG_NONE, nil, OPT_NO_COMPRESS},
949 //{"no-z", "", POPT_ARG_NONE, nil, OPT_NO_COMPRESS},
950 //{"compress-choice", "", POPT_ARG_STRING, &o.compress_choice, 0},
951 //{"zc", "", POPT_ARG_STRING, &o.compress_choice, 0},
952 //{"skip-compress", "", POPT_ARG_STRING, &o.skip_compress, 0},
953 //{"compress-level", "", POPT_ARG_INT, &o.do_compression_level, 0},
954 //{"zl", "", POPT_ARG_INT, &o.do_compression_level, 0},
955
956 //{"", "P", POPT_ARG_NONE, nil, 'P'},
957 {"progress", "", POPT_ARG_VAL, &o.do_progress, 1},
958 {"no-progress", "", POPT_ARG_VAL, &o.do_progress, 0},
959 //{"partial", "", POPT_ARG_VAL, &o.keep_partial, 1},
960 //{"no-partial", "", POPT_ARG_VAL, &o.keep_partial, 0},
961 //{"partial-dir", "", POPT_ARG_STRING, &o.partial_dir, 0},
962 //{"delay-updates", "", POPT_ARG_VAL, &o.delay_updates, 1},
963 //{"no-delay-updates", "", POPT_ARG_VAL, &o.delay_updates, 0},
964 //{"prune-empty-dirs", "m", POPT_ARG_VAL, &o.prune_empty_dirs, 1},
965 //{"no-prune-empty-dirs", "", POPT_ARG_VAL, &o.prune_empty_dirs, 0},
966 //{"no-m", "", POPT_ARG_VAL, &o.prune_empty_dirs, 0},
967 //{"log-file", "", POPT_ARG_STRING, &o.logfile_name, 0},
968 //{"log-file-format", "", POPT_ARG_STRING, &o.logfile_format, 0},
969 //{"out-format", "", POPT_ARG_STRING, &o.stdout_format, 0},
970 //{"log-format", "", POPT_ARG_STRING, &o.stdout_format, 0}, /* DEPRECATED */
971 //{"itemize-changes", "i", POPT_ARG_NONE, nil, 'i'},
972 //{"no-itemize-changes", "", POPT_ARG_VAL, &o.itemize_changes, 0},
973 //{"no-i", "", POPT_ARG_VAL, &o.itemize_changes, 0},
974 //{"bwlimit", "", POPT_ARG_STRING, &o.bwlimit_arg, OPT_BWLIMIT},
975 //{"no-bwlimit", "", POPT_ARG_VAL, &o.bwlimit, 0},
976 //{"backup", "b", POPT_ARG_VAL, &o.make_backups, 1},
977 //{"no-backup", "", POPT_ARG_VAL, &o.make_backups, 0},
978 //{"backup-dir", "", POPT_ARG_STRING, &o.backup_dir, 0},
979 //{"suffix", "", POPT_ARG_STRING, &o.backup_suffix, 0},
980 {"list-only", "", POPT_ARG_VAL, &o.list_only, 2},
981 //{"read-batch", "", POPT_ARG_STRING, &o.batch_name, OPT_READ_BATCH},
982 //{"write-batch", "", POPT_ARG_STRING, &o.batch_name, OPT_WRITE_BATCH},
983 //{"only-write-batch", "", POPT_ARG_STRING, &o.batch_name, OPT_ONLY_WRITE_BATCH},
984 //{"files-from", "", POPT_ARG_STRING, &o.files_from, 0},
985 //{"from0", "0", POPT_ARG_VAL, &o.eol_nulls, 1},
986 //{"no-from0", "", POPT_ARG_VAL, &o.eol_nulls, 0},
987 //{"old-args", "", POPT_ARG_NONE, nil, OPT_OLD_ARGS},
988 //{"no-old-args", "", POPT_ARG_VAL, &o.old_style_args, 0},
989 //{"secluded-args", "s", POPT_ARG_VAL, &o.protect_args, 1},
990 //{"no-secluded-args", "", POPT_ARG_VAL, &o.protect_args, 0},
991 //{"protect-args", "", POPT_ARG_VAL, &o.protect_args, 1},
992 //{"no-protect-args", "", POPT_ARG_VAL, &o.protect_args, 0},
993 //{"no-s", "", POPT_ARG_VAL, &o.protect_args, 0},
994 //{"trust-sender", "", POPT_ARG_VAL, &o.trust_sender, 1},
995 //{"numeric-ids", "", POPT_ARG_VAL, &o.numeric_ids, 1},
996 //{"no-numeric-ids", "", POPT_ARG_VAL, &o.numeric_ids, 0},
997 //{"usermap", "", POPT_ARG_STRING, nil, OPT_USERMAP},
998 //{"groupmap", "", POPT_ARG_STRING, nil, OPT_GROUPMAP},
999 //{"chown", "", POPT_ARG_STRING, nil, OPT_CHOWN},
1000 //{"timeout", "", POPT_ARG_INT, &o.io_timeout, 0},
1001 //{"no-timeout", "", POPT_ARG_VAL, &o.io_timeout, 0},
1002 {"contimeout", "", POPT_ARG_INT, &o.connect_timeout, 0},
1003 {"no-contimeout", "", POPT_ARG_VAL, &o.connect_timeout, 0},
1004 {"fsync", "", POPT_ARG_NONE, &o.do_fsync, 0},
1005 //{"stop-after", "", POPT_ARG_STRING, nil, OPT_STOP_AFTER},
1006 //{"time-limit", "", POPT_ARG_STRING, nil, OPT_STOP_AFTER}, /* earlier stop-after name */
1007 //{"stop-at", "", POPT_ARG_STRING, nil, OPT_STOP_AT},
1008 {"rsh", "e", POPT_ARG_STRING, &o.shell_cmd, 0},
1009 //{"rsync-path", "", POPT_ARG_STRING, &o.rsync_path, 0},
1010 //{"temp-dir", "T", POPT_ARG_STRING, &o.tmpdir, 0},
1011 //{"iconv", "", POPT_ARG_STRING, &o.iconv_opt, 0},
1012 //{"no-iconv", "", POPT_ARG_NONE, nil, OPT_NO_ICONV},
1013 //{"ipv4", "4", POPT_ARG_VAL, &o.default_af_hint, syscall.AF_INET},
1014 //{"ipv6", "6", POPT_ARG_VAL, &o.default_af_hint, syscall.AF_INET6},
1015 //{"8-bit-output", "8", POPT_ARG_VAL, &o.allow_8bit_chars, 1},
1016 //{"no-8-bit-output", "", POPT_ARG_VAL, &o.allow_8bit_chars, 0},
1017 //{"no-8", "", POPT_ARG_VAL, &o.allow_8bit_chars, 0},
1018 //{"mkpath", "", POPT_ARG_VAL, &o.mkpath_dest_arg, 1},
1019 //{"no-mkpath", "", POPT_ARG_VAL, &o.mkpath_dest_arg, 0},
1020 //{"qsort", "", POPT_ARG_NONE, &o.use_qsort, 0},
1021 //{"copy-as", "", POPT_ARG_STRING, &o.copy_as, 0},
1022 //{"address", "", POPT_ARG_STRING, &o.bind_address, 0},
1023 {"port", "", POPT_ARG_INT, &o.rsync_port, 0},
1024 //{"sockopts", "", POPT_ARG_STRING, &o.sockopts, 0},
1025 //{"password-file", "", POPT_ARG_STRING, &o.password_file, 0},
1026 //{"early-input", "", POPT_ARG_STRING, &o.early_input_file, 0},
1027 //{"blocking-io", "", POPT_ARG_VAL, &o.blocking_io, 1},
1028 //{"no-blocking-io", "", POPT_ARG_VAL, &o.blocking_io, 0},
1029 //{"outbuf", "", POPT_ARG_STRING, &o.outbuf_mode, 0},
1030 //{"remote-option", "M", POPT_ARG_STRING, nil, 'M'},
1031 //{"protocol", "", POPT_ARG_INT, &o.protocol_version, 0},
1032 //{"checksum-seed", "", POPT_ARG_INT, &o.checksum_seed, 0},
1033 {"server", "", POPT_ARG_NONE, nil, OPT_SERVER},
1034 {"sender", "", POPT_ARG_NONE, nil, OPT_SENDER},
1035 /* All the following options switch us into daemon-mode option-parsing. */
1036 {"config", "", POPT_ARG_STRING, nil, OPT_DAEMON},
1037 {"daemon", "", POPT_ARG_NONE, nil, OPT_DAEMON},
1038 {"dparam", "", POPT_ARG_STRING, nil, OPT_DAEMON},
1039 {"detach", "", POPT_ARG_NONE, nil, OPT_DAEMON},
1040 {"no-detach", "", POPT_ARG_NONE, nil, OPT_DAEMON},
1041 }
1042 }
1043
1044 func (o *Options) tridgeTable() []poptOption {
1045 return []poptOption{
1046 /* longName, shortName, argInfo, arg, val */
1047 {"help", "", POPT_ARG_NONE, nil, OPT_HELP},
1048 {"version", "V", POPT_ARG_NONE, nil, 'V'},
1049 {"verbose", "v", POPT_ARG_NONE, nil, 'v'},
1050 {"no-verbose", "", POPT_ARG_VAL, &o.verbose, 0},
1051 {"no-v", "", POPT_ARG_VAL, &o.verbose, 0},
1052 {"info", "", POPT_ARG_STRING, nil, OPT_INFO},
1053 {"debug", "", POPT_ARG_STRING, nil, OPT_DEBUG},
1054 {"stderr", "", POPT_ARG_STRING, nil, OPT_STDERR},
1055 {"msgs2stderr", "", POPT_ARG_VAL, &o.msgs2stderr, 1},
1056 {"no-msgs2stderr", "", POPT_ARG_VAL, &o.msgs2stderr, 0},
1057 {"quiet", "q", POPT_ARG_NONE, nil, 'q'},
1058 {"motd", "", POPT_ARG_VAL, &o.output_motd, 1},
1059 {"no-motd", "", POPT_ARG_VAL, &o.output_motd, 0},
1060 {"stats", "", POPT_ARG_NONE, &o.do_stats, 0},
1061 {"human-readable", "h", POPT_ARG_NONE, nil, 'h'},
1062 {"no-human-readable", "", POPT_ARG_VAL, &o.human_readable, 0},
1063 {"no-h", "", POPT_ARG_VAL, &o.human_readable, 0},
1064 {"dry-run", "n", POPT_ARG_NONE, &o.dry_run, 0},
1065 {"archive", "a", POPT_ARG_NONE, nil, 'a'},
1066 {"recursive", "r", POPT_ARG_VAL, &o.recurse, 2},
1067 {"no-recursive", "", POPT_ARG_VAL, &o.recurse, 0},
1068 {"no-r", "", POPT_ARG_VAL, &o.recurse, 0},
1069 {"inc-recursive", "", POPT_ARG_VAL, &o.allow_inc_recurse, 1},
1070 {"no-inc-recursive", "", POPT_ARG_VAL, &o.allow_inc_recurse, 0},
1071 {"i-r", "", POPT_ARG_VAL, &o.allow_inc_recurse, 1},
1072 {"no-i-r", "", POPT_ARG_VAL, &o.allow_inc_recurse, 0},
1073 {"dirs", "d", POPT_ARG_VAL, &o.xfer_dirs, 2},
1074 {"no-dirs", "", POPT_ARG_VAL, &o.xfer_dirs, 0},
1075 {"no-d", "", POPT_ARG_VAL, &o.xfer_dirs, 0},
1076 {"old-dirs", "", POPT_ARG_VAL, &o.xfer_dirs, 4},
1077 {"old-d", "", POPT_ARG_VAL, &o.xfer_dirs, 4},
1078 {"perms", "p", POPT_ARG_VAL, &o.preserve_perms, 1},
1079 {"no-perms", "", POPT_ARG_VAL, &o.preserve_perms, 0},
1080 {"no-p", "", POPT_ARG_VAL, &o.preserve_perms, 0},
1081 {"executability", "E", POPT_ARG_NONE, &o.preserve_executability, 0},
1082 {"acls", "A", POPT_ARG_NONE, nil, 'A'},
1083 {"no-acls", "", POPT_ARG_VAL, &o.preserve_acls, 0},
1084 {"no-A", "", POPT_ARG_VAL, &o.preserve_acls, 0},
1085 {"xattrs", "X", POPT_ARG_NONE, nil, 'X'},
1086 {"no-xattrs", "", POPT_ARG_VAL, &o.preserve_xattrs, 0},
1087 {"no-X", "", POPT_ARG_VAL, &o.preserve_xattrs, 0},
1088 {"times", "t", POPT_ARG_VAL, &o.preserve_mtimes, 1},
1089 {"no-times", "", POPT_ARG_VAL, &o.preserve_mtimes, 0},
1090 {"no-t", "", POPT_ARG_VAL, &o.preserve_mtimes, 0},
1091 {"atimes", "U", POPT_ARG_NONE, nil, 'U'},
1092 {"no-atimes", "", POPT_ARG_VAL, &o.preserve_atimes, 0},
1093 {"no-U", "", POPT_ARG_VAL, &o.preserve_atimes, 0},
1094 {"open-noatime", "", POPT_ARG_VAL, &o.open_noatime, 1},
1095 {"no-open-noatime", "", POPT_ARG_VAL, &o.open_noatime, 0},
1096 {"crtimes", "N", POPT_ARG_NONE, &o.preserve_crtimes, 1}, // refused
1097 {"no-crtimes", "", POPT_ARG_VAL, &o.preserve_crtimes, 0},
1098 {"no-N", "", POPT_ARG_VAL, &o.preserve_crtimes, 0},
1099 {"omit-dir-times", "O", POPT_ARG_VAL, &o.omit_dir_times, 1},
1100 {"no-omit-dir-times", "", POPT_ARG_VAL, &o.omit_dir_times, 0},
1101 {"no-O", "", POPT_ARG_VAL, &o.omit_dir_times, 0},
1102 {"omit-link-times", "J", POPT_ARG_VAL, &o.omit_link_times, 1},
1103 {"no-omit-link-times", "", POPT_ARG_VAL, &o.omit_link_times, 0},
1104 {"no-J", "", POPT_ARG_VAL, &o.omit_link_times, 0},
1105 {"modify-window", "@", POPT_ARG_INT, &o.modify_window, OPT_MODIFY_WINDOW},
1106 {"super", "", POPT_ARG_VAL, &o.am_root, 2},
1107 {"no-super", "", POPT_ARG_VAL, &o.am_root, 0},
1108 {"fake-super", "", POPT_ARG_VAL, &o.am_root, -1},
1109 {"owner", "o", POPT_ARG_VAL, &o.preserve_uid, 1},
1110 {"no-owner", "", POPT_ARG_VAL, &o.preserve_uid, 0},
1111 {"no-o", "", POPT_ARG_VAL, &o.preserve_uid, 0},
1112 {"group", "g", POPT_ARG_VAL, &o.preserve_gid, 1},
1113 {"no-group", "", POPT_ARG_VAL, &o.preserve_gid, 0},
1114 {"no-g", "", POPT_ARG_VAL, &o.preserve_gid, 0},
1115 {"", "D", POPT_ARG_NONE, nil, 'D'},
1116 {"no-D", "", POPT_ARG_NONE, nil, OPT_NO_D},
1117 {"devices", "", POPT_ARG_VAL, &o.preserve_devices, 1},
1118 {"no-devices", "", POPT_ARG_VAL, &o.preserve_devices, 0},
1119 {"copy-devices", "", POPT_ARG_NONE, &o.copy_devices, 0},
1120 {"write-devices", "", POPT_ARG_VAL, &o.write_devices, 1},
1121 {"no-write-devices", "", POPT_ARG_VAL, &o.write_devices, 0},
1122 {"specials", "", POPT_ARG_VAL, &o.preserve_specials, 1},
1123 {"no-specials", "", POPT_ARG_VAL, &o.preserve_specials, 0},
1124 {"links", "l", POPT_ARG_VAL, &o.preserve_links, 1},
1125 {"no-links", "", POPT_ARG_VAL, &o.preserve_links, 0},
1126 {"no-l", "", POPT_ARG_VAL, &o.preserve_links, 0},
1127 {"copy-links", "L", POPT_ARG_NONE, &o.copy_links, 0},
1128 {"copy-unsafe-links", "", POPT_ARG_NONE, &o.copy_unsafe_links, 0},
1129 {"safe-links", "", POPT_ARG_NONE, &o.safe_symlinks, 0},
1130 {"munge-links", "", POPT_ARG_VAL, &o.munge_symlinks, 1},
1131 {"no-munge-links", "", POPT_ARG_VAL, &o.munge_symlinks, 0},
1132 {"copy-dirlinks", "k", POPT_ARG_NONE, &o.copy_dirlinks, 0},
1133 {"keep-dirlinks", "K", POPT_ARG_NONE, &o.keep_dirlinks, 0},
1134 {"hard-links", "H", POPT_ARG_NONE, nil, 'H'},
1135 {"no-hard-links", "", POPT_ARG_VAL, &o.preserve_hard_links, 0},
1136 {"no-H", "", POPT_ARG_VAL, &o.preserve_hard_links, 0},
1137 {"relative", "R", POPT_ARG_VAL, &o.relative_paths, 1},
1138 {"no-relative", "", POPT_ARG_VAL, &o.relative_paths, 0},
1139 {"no-R", "", POPT_ARG_VAL, &o.relative_paths, 0},
1140 {"implied-dirs", "", POPT_ARG_VAL, &o.implied_dirs, 1},
1141 {"no-implied-dirs", "", POPT_ARG_VAL, &o.implied_dirs, 0},
1142 {"i-d", "", POPT_ARG_VAL, &o.implied_dirs, 1},
1143 {"no-i-d", "", POPT_ARG_VAL, &o.implied_dirs, 0},
1144 {"chmod", "", POPT_ARG_STRING, nil, OPT_CHMOD},
1145 {"ignore-times", "I", POPT_ARG_NONE, &o.ignore_times, 0},
1146 {"size-only", "", POPT_ARG_NONE, &o.size_only, 0},
1147 {"one-file-system", "x", POPT_ARG_NONE, nil, 'x'},
1148 {"no-one-file-system", "", POPT_ARG_VAL, &o.one_file_system, 0},
1149 {"no-x", "", POPT_ARG_VAL, &o.one_file_system, 0},
1150 {"update", "u", POPT_ARG_NONE, &o.update_only, 0},
1151 {"existing", "", POPT_ARG_NONE, &o.ignore_non_existing, 0},
1152 {"ignore-non-existing", "", POPT_ARG_NONE, &o.ignore_non_existing, 0},
1153 {"ignore-existing", "", POPT_ARG_NONE, &o.ignore_existing, 0},
1154 {"max-size", "", POPT_ARG_STRING, &o.max_size_arg, OPT_MAX_SIZE},
1155 {"min-size", "", POPT_ARG_STRING, &o.min_size_arg, OPT_MIN_SIZE},
1156 {"max-alloc", "", POPT_ARG_STRING, &o.max_alloc_arg, 0},
1157 {"sparse", "S", POPT_ARG_VAL, &o.sparse_files, 1},
1158 {"no-sparse", "", POPT_ARG_VAL, &o.sparse_files, 0},
1159 {"no-S", "", POPT_ARG_VAL, &o.sparse_files, 0},
1160 {"preallocate", "", POPT_ARG_NONE, &o.preallocate_files, 0},
1161 {"inplace", "", POPT_ARG_VAL, &o.inplace, 1},
1162 {"no-inplace", "", POPT_ARG_VAL, &o.inplace, 0},
1163 {"append", "", POPT_ARG_NONE, nil, OPT_APPEND},
1164 {"append-verify", "", POPT_ARG_VAL, &o.append_mode, 2},
1165 {"no-append", "", POPT_ARG_VAL, &o.append_mode, 0},
1166 {"del", "", POPT_ARG_NONE, &o.delete_during, 0},
1167 {"delete", "", POPT_ARG_NONE, &o.delete_mode, 0},
1168 {"delete-before", "", POPT_ARG_NONE, &o.delete_before, 0},
1169 {"delete-during", "", POPT_ARG_VAL, &o.delete_during, 1},
1170 {"delete-delay", "", POPT_ARG_VAL, &o.delete_during, 2},
1171 {"delete-after", "", POPT_ARG_NONE, &o.delete_after, 0},
1172 {"delete-excluded", "", POPT_ARG_NONE, &o.delete_excluded, 0},
1173 {"delete-missing-args", "", POPT_BIT_SET, &o.missing_args, 2},
1174 {"ignore-missing-args", "", POPT_BIT_SET, &o.missing_args, 1},
1175 {"remove-sent-files", "", POPT_ARG_VAL, &o.remove_source_files, 2}, /* deprecated */
1176 {"remove-source-files", "", POPT_ARG_VAL, &o.remove_source_files, 1},
1177 {"force", "", POPT_ARG_VAL, &o.force_delete, 1},
1178 {"no-force", "", POPT_ARG_VAL, &o.force_delete, 0},
1179 {"ignore-errors", "", POPT_ARG_VAL, &o.ignore_errors, 1},
1180 {"no-ignore-errors", "", POPT_ARG_VAL, &o.ignore_errors, 0},
1181 {"max-delete", "", POPT_ARG_INT, &o.max_delete, 0},
1182 {"", "F", POPT_ARG_NONE, nil, 'F'},
1183 {"filter", "f", POPT_ARG_STRING, nil, OPT_FILTER},
1184 {"exclude", "", POPT_ARG_STRING, nil, OPT_EXCLUDE},
1185 {"include", "", POPT_ARG_STRING, nil, OPT_INCLUDE},
1186 {"exclude-from", "", POPT_ARG_STRING, nil, OPT_EXCLUDE_FROM},
1187 {"include-from", "", POPT_ARG_STRING, nil, OPT_INCLUDE_FROM},
1188 {"cvs-exclude", "C", POPT_ARG_NONE, &o.cvs_exclude, 0},
1189 {"whole-file", "W", POPT_ARG_VAL, &o.whole_file, 1},
1190 {"no-whole-file", "", POPT_ARG_VAL, &o.whole_file, 0},
1191 {"no-W", "", POPT_ARG_VAL, &o.whole_file, 0},
1192 {"checksum", "c", POPT_ARG_VAL, &o.always_checksum, 1},
1193 {"no-checksum", "", POPT_ARG_VAL, &o.always_checksum, 0},
1194 {"no-c", "", POPT_ARG_VAL, &o.always_checksum, 0},
1195 {"checksum-choice", "", POPT_ARG_STRING, &o.checksum_choice, 0},
1196 {"cc", "", POPT_ARG_STRING, &o.checksum_choice, 0},
1197 {"block-size", "B", POPT_ARG_STRING, nil, OPT_BLOCK_SIZE},
1198 {"compare-dest", "", POPT_ARG_STRING, nil, OPT_COMPARE_DEST},
1199 {"copy-dest", "", POPT_ARG_STRING, nil, OPT_COPY_DEST},
1200 {"link-dest", "", POPT_ARG_STRING, nil, OPT_LINK_DEST},
1201 {"fuzzy", "y", POPT_ARG_NONE, nil, 'y'},
1202 {"no-fuzzy", "", POPT_ARG_VAL, &o.fuzzy_basis, 0},
1203 {"no-y", "", POPT_ARG_VAL, &o.fuzzy_basis, 0},
1204 {"compress", "z", POPT_ARG_NONE, nil, 'z'},
1205 {"old-compress", "", POPT_ARG_NONE, nil, OPT_OLD_COMPRESS},
1206 {"new-compress", "", POPT_ARG_NONE, nil, OPT_NEW_COMPRESS},
1207 {"no-compress", "", POPT_ARG_NONE, nil, OPT_NO_COMPRESS},
1208 {"no-z", "", POPT_ARG_NONE, nil, OPT_NO_COMPRESS},
1209 {"compress-choice", "", POPT_ARG_STRING, &o.compress_choice, 0},
1210 {"zc", "", POPT_ARG_STRING, &o.compress_choice, 0},
1211 {"skip-compress", "", POPT_ARG_STRING, &o.skip_compress, 0},
1212 {"compress-level", "", POPT_ARG_INT, &o.do_compression_level, 0},
1213 {"zl", "", POPT_ARG_INT, &o.do_compression_level, 0},
1214 {"", "P", POPT_ARG_NONE, nil, 'P'},
1215 {"progress", "", POPT_ARG_VAL, &o.do_progress, 1},
1216 {"no-progress", "", POPT_ARG_VAL, &o.do_progress, 0},
1217 {"partial", "", POPT_ARG_VAL, &o.keep_partial, 1},
1218 {"no-partial", "", POPT_ARG_VAL, &o.keep_partial, 0},
1219 {"partial-dir", "", POPT_ARG_STRING, &o.partial_dir, 0},
1220 {"delay-updates", "", POPT_ARG_VAL, &o.delay_updates, 1},
1221 {"no-delay-updates", "", POPT_ARG_VAL, &o.delay_updates, 0},
1222 {"prune-empty-dirs", "m", POPT_ARG_VAL, &o.prune_empty_dirs, 1},
1223 {"no-prune-empty-dirs", "", POPT_ARG_VAL, &o.prune_empty_dirs, 0},
1224 {"no-m", "", POPT_ARG_VAL, &o.prune_empty_dirs, 0},
1225 {"log-file", "", POPT_ARG_STRING, &o.logfile_name, 0},
1226 {"log-file-format", "", POPT_ARG_STRING, &o.logfile_format, 0},
1227 {"out-format", "", POPT_ARG_STRING, &o.stdout_format, 0},
1228 {"log-format", "", POPT_ARG_STRING, &o.stdout_format, 0}, /* DEPRECATED */
1229 {"itemize-changes", "i", POPT_ARG_NONE, nil, 'i'},
1230 {"no-itemize-changes", "", POPT_ARG_VAL, &o.itemize_changes, 0},
1231 {"no-i", "", POPT_ARG_VAL, &o.itemize_changes, 0},
1232 {"bwlimit", "", POPT_ARG_STRING, &o.bwlimit_arg, OPT_BWLIMIT},
1233 {"no-bwlimit", "", POPT_ARG_VAL, &o.bwlimit, 0},
1234 {"backup", "b", POPT_ARG_VAL, &o.make_backups, 1},
1235 {"no-backup", "", POPT_ARG_VAL, &o.make_backups, 0},
1236 {"backup-dir", "", POPT_ARG_STRING, &o.backup_dir, 0},
1237 {"suffix", "", POPT_ARG_STRING, &o.backup_suffix, 0},
1238 {"list-only", "", POPT_ARG_VAL, &o.list_only, 2},
1239 {"read-batch", "", POPT_ARG_STRING, &o.batch_name, OPT_READ_BATCH},
1240 {"write-batch", "", POPT_ARG_STRING, &o.batch_name, OPT_WRITE_BATCH},
1241 {"only-write-batch", "", POPT_ARG_STRING, &o.batch_name, OPT_ONLY_WRITE_BATCH},
1242 {"files-from", "", POPT_ARG_STRING, &o.files_from, 0},
1243 {"from0", "0", POPT_ARG_VAL, &o.eol_nulls, 1},
1244 {"no-from0", "", POPT_ARG_VAL, &o.eol_nulls, 0},
1245 {"old-args", "", POPT_ARG_NONE, nil, OPT_OLD_ARGS},
1246 {"no-old-args", "", POPT_ARG_VAL, &o.old_style_args, 0},
1247 {"secluded-args", "s", POPT_ARG_VAL, &o.protect_args, 1},
1248 {"no-secluded-args", "", POPT_ARG_VAL, &o.protect_args, 0},
1249 {"protect-args", "", POPT_ARG_VAL, &o.protect_args, 1},
1250 {"no-protect-args", "", POPT_ARG_VAL, &o.protect_args, 0},
1251 {"no-s", "", POPT_ARG_VAL, &o.protect_args, 0},
1252 {"trust-sender", "", POPT_ARG_VAL, &o.trust_sender, 1},
1253 {"numeric-ids", "", POPT_ARG_VAL, &o.numeric_ids, 1},
1254 {"no-numeric-ids", "", POPT_ARG_VAL, &o.numeric_ids, 0},
1255 {"usermap", "", POPT_ARG_STRING, nil, OPT_USERMAP},
1256 {"groupmap", "", POPT_ARG_STRING, nil, OPT_GROUPMAP},
1257 {"chown", "", POPT_ARG_STRING, nil, OPT_CHOWN},
1258 {"timeout", "", POPT_ARG_INT, &o.io_timeout, 0},
1259 {"no-timeout", "", POPT_ARG_VAL, &o.io_timeout, 0},
1260 {"contimeout", "", POPT_ARG_INT, &o.connect_timeout, 0},
1261 {"no-contimeout", "", POPT_ARG_VAL, &o.connect_timeout, 0},
1262 {"fsync", "", POPT_ARG_NONE, &o.do_fsync, 0},
1263 {"stop-after", "", POPT_ARG_STRING, nil, OPT_STOP_AFTER},
1264 {"time-limit", "", POPT_ARG_STRING, nil, OPT_STOP_AFTER}, /* earlier stop-after name */
1265 {"stop-at", "", POPT_ARG_STRING, nil, OPT_STOP_AT},
1266 {"rsh", "e", POPT_ARG_STRING, &o.shell_cmd, 0},
1267 {"rsync-path", "", POPT_ARG_STRING, &o.rsync_path, 0},
1268 {"temp-dir", "T", POPT_ARG_STRING, &o.tmpdir, 0},
1269 {"iconv", "", POPT_ARG_STRING, &o.iconv_opt, 0},
1270 {"no-iconv", "", POPT_ARG_NONE, nil, OPT_NO_ICONV},
1271 {"ipv4", "4", POPT_ARG_VAL, &o.default_af_hint, syscall.AF_INET},
1272 {"ipv6", "6", POPT_ARG_VAL, &o.default_af_hint, syscall.AF_INET6},
1273 {"8-bit-output", "8", POPT_ARG_VAL, &o.allow_8bit_chars, 1},
1274 {"no-8-bit-output", "", POPT_ARG_VAL, &o.allow_8bit_chars, 0},
1275 {"no-8", "", POPT_ARG_VAL, &o.allow_8bit_chars, 0},
1276 {"mkpath", "", POPT_ARG_VAL, &o.mkpath_dest_arg, 1},
1277 {"no-mkpath", "", POPT_ARG_VAL, &o.mkpath_dest_arg, 0},
1278 {"qsort", "", POPT_ARG_NONE, &o.use_qsort, 0},
1279 {"copy-as", "", POPT_ARG_STRING, &o.copy_as, 0},
1280 {"address", "", POPT_ARG_STRING, &o.bind_address, 0},
1281 {"port", "", POPT_ARG_INT, &o.rsync_port, 0},
1282 {"sockopts", "", POPT_ARG_STRING, &o.sockopts, 0},
1283 {"password-file", "", POPT_ARG_STRING, &o.password_file, 0},
1284 {"early-input", "", POPT_ARG_STRING, &o.early_input_file, 0},
1285 {"blocking-io", "", POPT_ARG_VAL, &o.blocking_io, 1},
1286 {"no-blocking-io", "", POPT_ARG_VAL, &o.blocking_io, 0},
1287 {"outbuf", "", POPT_ARG_STRING, &o.outbuf_mode, 0},
1288 {"remote-option", "M", POPT_ARG_STRING, nil, 'M'},
1289 {"protocol", "", POPT_ARG_INT, &o.protocol_version, 0},
1290 {"checksum-seed", "", POPT_ARG_INT, &o.checksum_seed, 0},
1291 {"server", "", POPT_ARG_NONE, nil, OPT_SERVER},
1292 {"sender", "", POPT_ARG_NONE, nil, OPT_SENDER},
1293 /* All the following options switch us into daemon-mode option-parsing. */
1294 {"config", "", POPT_ARG_STRING, nil, OPT_DAEMON},
1295 {"daemon", "", POPT_ARG_NONE, nil, OPT_DAEMON},
1296 {"dparam", "", POPT_ARG_STRING, nil, OPT_DAEMON},
1297 {"detach", "", POPT_ARG_NONE, nil, OPT_DAEMON},
1298 {"no-detach", "", POPT_ARG_NONE, nil, OPT_DAEMON},
1299 }
1300 }
1301
1302 var errNotYetImplemented = errors.New("option not yet implemented in gokrazy/rsync")
1303
1304 func NewContext(opts *Options) *Context {
1305 table := opts.table()
1306 table = slices.Concat(opts.GokrazyClient.table(), table)
1307 return &Context{
1308 Options: opts,
1309 table: table,
1310 }
1311 }
1312
1313 // rsync/options.c:parse_arguments
1314 func (pc *Context) ParseArguments(osenv *rsyncos.Env, args []string) error {
1315 // NOTE: We do not implement support for refusing options per rsyncd.conf
1316 // here, as we have our own configuration file.
1317
1318 version_opt_cnt := 0
1319
1320 pc.args = args
1321 opts := pc.Options
1322
1323 for {
1324 opt, err := pc.poptGetNextOpt()
1325 if err != nil {
1326 return err
1327 }
1328 if opt == -1 {
1329 break // done
1330 }
1331 // Most options are handled by poptGetNextOpt, only special cases
1332 // are returned and handled here.
1333 switch opt {
1334 case 'V':
1335 version_opt_cnt++
1336
1337 case OPT_SERVER:
1338 opts.am_server = 1
1339
1340 case OPT_SENDER:
1341 if opts.am_server == 0 {
1342 return fmt.Errorf("--sender only allowed with --server")
1343 }
1344 opts.am_sender = 1
1345
1346 case OPT_DAEMON:
1347 // Parse the whole command-line using the daemon options table.
1348 table := opts.daemonTable()
1349 table = slices.Concat(opts.GokrazyDaemon.table(), table)
1350 pc := Context{
1351 Options: opts,
1352 table: table,
1353 args: args,
1354 }
1355
1356 for {
1357 opt, err := pc.poptGetNextOpt()
1358 if err != nil {
1359 err.(*PoptError).DaemonMode = true
1360 return err
1361 }
1362 if opt == -1 {
1363 break // done
1364 }
1365 // Most options are handled by poptGetNextOpt, only special cases
1366 // are returned and handled here.
1367 switch opt {
1368 case 'h':
1369 fmt.Println(opts.DaemonHelp()) // tridge rsync prints help to stdout
1370 os.Exit(0) // exit with code 0 for compatibility with tridge rsync
1371 case 'M':
1372 return errNotYetImplemented
1373
1374 case 'v':
1375 opts.verbose++
1376
1377 default:
1378 return fmt.Errorf("unhandled special case opt: %v", opt)
1379 }
1380 }
1381
1382 opts.am_daemon = 1
1383
1384 return nil
1385
1386 case OPT_FILTER:
1387 opts.filterRules = append(opts.filterRules, pc.poptGetOptArg())
1388 case OPT_EXCLUDE:
1389 opts.filterRules = append(opts.filterRules, "- "+pc.poptGetOptArg())
1390 case OPT_INCLUDE:
1391 opts.filterRules = append(opts.filterRules, "+ "+pc.poptGetOptArg())
1392
1393 case OPT_INCLUDE_FROM,
1394 OPT_EXCLUDE_FROM:
1395 return errNotYetImplemented
1396
1397 case 'a':
1398 if opts.recurse == 0 {
1399 opts.recurse = 1
1400 }
1401 opts.preserve_links = 1
1402 opts.preserve_perms = 1
1403 opts.preserve_mtimes = 1
1404 opts.preserve_gid = 1
1405 opts.preserve_uid = 1
1406 opts.preserve_devices = 1
1407 opts.preserve_specials = 1
1408
1409 case 'D':
1410 opts.preserve_devices = 1
1411 opts.preserve_specials = 1
1412
1413 case OPT_NO_D:
1414 opts.preserve_devices = 0
1415 opts.preserve_specials = 0
1416
1417 case 'h':
1418 opts.human_readable++
1419
1420 case 'H':
1421 opts.preserve_hard_links = 1
1422
1423 case 'i':
1424 opts.itemize_changes++
1425
1426 case 'U':
1427 opts.preserve_atimes++
1428 if opts.preserve_atimes > 1 {
1429 opts.open_noatime = 1
1430 }
1431
1432 case 'v':
1433 opts.verbose++
1434
1435 case 'y':
1436 return errNotYetImplemented
1437
1438 case 'q':
1439 opts.quiet++
1440
1441 case 'x':
1442 opts.one_file_system++
1443
1444 case 'F':
1445 return errNotYetImplemented
1446
1447 case 'P':
1448 opts.do_progress = 1
1449 opts.keep_partial = 1
1450
1451 case 'z':
1452 opts.do_compression++
1453
1454 case OPT_OLD_COMPRESS:
1455 opts.compress_choice = "zlib"
1456
1457 case OPT_NEW_COMPRESS:
1458 opts.compress_choice = "zlibx"
1459
1460 case OPT_NO_COMPRESS:
1461 opts.do_compression = 0
1462 opts.compress_choice = ""
1463
1464 case OPT_OLD_ARGS:
1465 return errNotYetImplemented
1466
1467 case 'M': // --remote-option
1468 return errNotYetImplemented
1469
1470 case OPT_WRITE_BATCH,
1471 OPT_ONLY_WRITE_BATCH,
1472 OPT_READ_BATCH:
1473 return errNotYetImplemented
1474
1475 case OPT_BLOCK_SIZE:
1476 return errNotYetImplemented
1477
1478 case OPT_MAX_SIZE, // (needs parse_size_arg)
1479 OPT_MIN_SIZE,
1480 OPT_BWLIMIT:
1481 return errNotYetImplemented
1482
1483 case OPT_APPEND:
1484 return errNotYetImplemented
1485
1486 case OPT_LINK_DEST,
1487 OPT_COPY_DEST,
1488 OPT_COMPARE_DEST:
1489 return errNotYetImplemented
1490
1491 case OPT_CHMOD: // (needs parse_chmod):
1492 return errNotYetImplemented
1493
1494 case OPT_INFO:
1495 parseOutputWords(osenv, infoWords[:], opts.info[:], pc.poptGetOptArg(), USER_PRIORITY)
1496
1497 case OPT_DEBUG:
1498 parseOutputWords(osenv, debugWords[:], opts.debug[:], pc.poptGetOptArg(), USER_PRIORITY)
1499
1500 case OPT_USERMAP,
1501 OPT_GROUPMAP,
1502 OPT_CHOWN:
1503 return errNotYetImplemented
1504
1505 case OPT_HELP:
1506 fmt.Println(opts.Help()) // tridge rsync prints help to stdout
1507 os.Exit(0) // exit with code 0 for compatibility with tridge rsync
1508
1509 case 'A':
1510 return fmt.Errorf("ACLs are not supported by gokrazy/rsync")
1511
1512 case 'X':
1513 opts.preserve_xattrs++
1514
1515 case OPT_STOP_AFTER,
1516 OPT_STOP_AT,
1517 OPT_STDERR:
1518 return errNotYetImplemented
1519
1520 default:
1521 return fmt.Errorf("unhandled special case opt: %v", opt)
1522 }
1523 }
1524
1525 // rsync/options.c line 1973 and following set option defaults based on
1526 // other options
1527
1528 if version_opt_cnt > 0 {
1529 fmt.Println(version.Read())
1530 os.Exit(0)
1531 }
1532
1533 if opts.human_readable > 1 && len(args) == 1 /* && !am_server */ {
1534 fmt.Println(opts.Help()) // tridge rsync prints help to stdout
1535 os.Exit(0) // exit with code 0 for compatibility with tridge rsync
1536 }
1537
1538 if err := opts.setOutputVerbosity(DEFAULT_PRIORITY); err != nil {
1539 // TODO: plumb error
1540 fmt.Println(err.Error())
1541 os.Exit(1)
1542 }
1543
1544 if opts.recurse != 0 {
1545 opts.xfer_dirs = 1
1546 }
1547 if opts.xfer_dirs < 0 {
1548 if opts.list_only != 0 {
1549 opts.xfer_dirs = 1
1550 } else {
1551 opts.xfer_dirs = 0
1552 }
1553 }
1554
1555 if opts.relative_paths < 0 {
1556 if opts.files_from != "" {
1557 opts.relative_paths = 1
1558 } else {
1559 opts.relative_paths = 0
1560 }
1561 }
1562
1563 if opts.relative_paths == 0 {
1564 opts.implied_dirs = 0
1565 }
1566
1567 // NOTE: This simplification means that even if we ignore POPT_ARGFLAG_OR
1568 // and store ints without regards for bit sets, we get the same result.
1569 // Nevertheless, we support bit to be future-proof as new options are added.
1570 if opts.missing_args == 3 {
1571 // simplify if both options were specified
1572 opts.missing_args = 2
1573 }
1574
1575 if opts.backup_suffix == "" && opts.backup_dir == "" {
1576 opts.backup_suffix = "~"
1577 }
1578
1579 if opts.backup_dir != "" {
1580 opts.make_backups = 1 // --backup-dir implies --backup
1581 }
1582
1583 if opts.do_progress != 0 && opts.am_server == 0 {
1584 if opts.info[INFO_NAME] == 0 {
1585 opts.info[INFO_NAME] = 1
1586 }
1587 opts.info[INFO_FLIST] = 2
1588 opts.info[INFO_PROGRESS] = 1
1589 }
1590
1591 if opts.info[INFO_NAME] >= 1 && opts.stdout_format == "" {
1592 opts.stdout_format = "%n%L"
1593 }
1594
1595 return nil
1596 }