forked from rclone/rclone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
796 lines (764 loc) · 27 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
package fs
import (
"context"
"errors"
"fmt"
"net"
"os"
"strconv"
"strings"
"time"
)
// Global
var (
// globalConfig for rclone
globalConfig = new(ConfigInfo)
// Read a value from the config file
//
// This is a function pointer to decouple the config
// implementation from the fs
ConfigFileGet = func(section, key string) (string, bool) { return "", false }
// Set a value into the config file and persist it
//
// This is a function pointer to decouple the config
// implementation from the fs
ConfigFileSet = func(section, key, value string) (err error) {
return errors.New("no config file set handler")
}
// Check if the config file has the named section
//
// This is a function pointer to decouple the config
// implementation from the fs
ConfigFileHasSection = func(section string) bool { return false }
// CountError counts an error. If any errors have been
// counted then rclone will exit with a non zero error code.
//
// This is a function pointer to decouple the config
// implementation from the fs
CountError = func(ctx context.Context, err error) error { return err }
// ConfigProvider is the config key used for provider options
ConfigProvider = "provider"
// ConfigEdit is the config key used to show we wish to edit existing entries
ConfigEdit = "config_fs_edit"
)
// ConfigOptionsInfo describes the Options in use
var ConfigOptionsInfo = Options{{
Name: "modify_window",
Default: time.Nanosecond,
Help: "Max time diff to be considered the same",
Groups: "Copy",
}, {
Name: "checkers",
Default: 8,
Help: "Number of checkers to run in parallel",
Groups: "Performance",
}, {
Name: "transfers",
Default: 4,
Help: "Number of file transfers to run in parallel",
Groups: "Performance",
}, {
Name: "checksum",
ShortOpt: "c",
Default: false,
Help: "Check for changes with size & checksum (if available, or fallback to size only)",
Groups: "Copy",
}, {
Name: "size_only",
Default: false,
Help: "Skip based on size only, not modtime or checksum",
Groups: "Copy",
}, {
Name: "ignore_times",
ShortOpt: "I",
Default: false,
Help: "Don't skip items that match size and time - transfer all unconditionally",
Groups: "Copy",
}, {
Name: "ignore_existing",
Default: false,
Help: "Skip all files that exist on destination",
Groups: "Copy",
}, {
Name: "ignore_errors",
Default: false,
Help: "Delete even if there are I/O errors",
Groups: "Sync",
}, {
Name: "dry_run",
ShortOpt: "n",
Default: false,
Help: "Do a trial run with no permanent changes",
Groups: "Config,Important",
}, {
Name: "interactive",
ShortOpt: "i",
Default: false,
Help: "Enable interactive mode",
Groups: "Config,Important",
}, {
Name: "contimeout",
Default: 60 * time.Second,
Help: "Connect timeout",
Groups: "Networking",
}, {
Name: "timeout",
Default: 5 * 60 * time.Second,
Help: "IO idle timeout",
Groups: "Networking",
}, {
Name: "expect_continue_timeout",
Default: 1 * time.Second,
Help: "Timeout when using expect / 100-continue in HTTP",
Groups: "Networking",
}, {
Name: "no_check_certificate",
Default: false,
Help: "Do not verify the server SSL certificate (insecure)",
Groups: "Networking",
}, {
Name: "ask_password",
Default: true,
Help: "Allow prompt for password for encrypted configuration",
Groups: "Config",
}, {
Name: "password_command",
Default: SpaceSepList{},
Help: "Command for supplying password for encrypted configuration",
Groups: "Config",
}, {
Name: "max_delete",
Default: int64(-1),
Help: "When synchronizing, limit the number of deletes",
Groups: "Sync",
}, {
Name: "max_delete_size",
Default: SizeSuffix(-1),
Help: "When synchronizing, limit the total size of deletes",
Groups: "Sync",
}, {
Name: "track_renames",
Default: false,
Help: "When synchronizing, track file renames and do a server-side move if possible",
Groups: "Sync",
}, {
Name: "track_renames_strategy",
Default: "hash",
Help: "Strategies to use when synchronizing using track-renames hash|modtime|leaf",
Groups: "Sync",
}, {
Name: "retries",
Default: 3,
Help: "Retry operations this many times if they fail",
Groups: "Config",
}, {
Name: "retries_sleep",
Default: time.Duration(0),
Help: "Interval between retrying operations if they fail, e.g. 500ms, 60s, 5m (0 to disable)",
Groups: "Config",
}, {
Name: "low_level_retries",
Default: 10,
Help: "Number of low level retries to do",
Groups: "Config",
}, {
Name: "update",
ShortOpt: "u",
Default: false,
Help: "Skip files that are newer on the destination",
Groups: "Copy",
}, {
Name: "use_server_modtime",
Default: false,
Help: "Use server modified time instead of object metadata",
Groups: "Config",
}, {
Name: "no_gzip_encoding",
Default: false,
Help: "Don't set Accept-Encoding: gzip",
Groups: "Networking",
}, {
Name: "max_depth",
Default: -1,
Help: "If set limits the recursion depth to this",
Groups: "Filter",
}, {
Name: "ignore_size",
Default: false,
Help: "Ignore size when skipping use modtime or checksum",
Groups: "Copy",
}, {
Name: "ignore_checksum",
Default: false,
Help: "Skip post copy check of checksums",
Groups: "Copy",
}, {
Name: "ignore_case_sync",
Default: false,
Help: "Ignore case when synchronizing",
Groups: "Copy",
}, {
Name: "fix_case",
Default: false,
Help: "Force rename of case insensitive dest to match source",
Groups: "Sync",
}, {
Name: "no_traverse",
Default: false,
Help: "Don't traverse destination file system on copy",
Groups: "Copy",
}, {
Name: "check_first",
Default: false,
Help: "Do all the checks before starting transfers",
Groups: "Copy",
}, {
Name: "no_check_dest",
Default: false,
Help: "Don't check the destination, copy regardless",
Groups: "Copy",
}, {
Name: "no_unicode_normalization",
Default: false,
Help: "Don't normalize unicode characters in filenames",
Groups: "Config",
}, {
Name: "no_update_modtime",
Default: false,
Help: "Don't update destination modtime if files identical",
Groups: "Copy",
}, {
Name: "no_update_dir_modtime",
Default: false,
Help: "Don't update directory modification times",
Groups: "Copy",
}, {
Name: "compare_dest",
Default: []string{},
Help: "Include additional server-side paths during comparison",
Groups: "Copy",
}, {
Name: "copy_dest",
Default: []string{},
Help: "Implies --compare-dest but also copies files from paths into destination",
Groups: "Copy",
}, {
Name: "backup_dir",
Default: "",
Help: "Make backups into hierarchy based in DIR",
Groups: "Sync",
}, {
Name: "suffix",
Default: "",
Help: "Suffix to add to changed files",
Groups: "Sync",
}, {
Name: "suffix_keep_extension",
Default: false,
Help: "Preserve the extension when using --suffix",
Groups: "Sync",
}, {
Name: "fast_list",
Default: false,
Help: "Use recursive list if available; uses more memory but fewer transactions",
Groups: "Listing",
}, {
Name: "tpslimit",
Default: 0.0,
Help: "Limit HTTP transactions per second to this",
Groups: "Networking",
}, {
Name: "tpslimit_burst",
Default: 1,
Help: "Max burst of transactions for --tpslimit",
Groups: "Networking",
}, {
Name: "user_agent",
Default: "rclone/" + Version,
Help: "Set the user-agent to a specified string",
Groups: "Networking",
}, {
Name: "immutable",
Default: false,
Help: "Do not modify files, fail if existing files have been modified",
Groups: "Copy",
}, {
Name: "auto_confirm",
Default: false,
Help: "If enabled, do not request console confirmation",
Groups: "Config",
}, {
Name: "stats_unit",
Default: "bytes",
Help: "Show data rate in stats as either 'bits' or 'bytes' per second",
Groups: "Logging",
}, {
Name: "stats_file_name_length",
Default: 45,
Help: "Max file name length in stats (0 for no limit)",
Groups: "Logging",
}, {
Name: "log_level",
Default: LogLevelNotice,
Help: "Log level DEBUG|INFO|NOTICE|ERROR",
Groups: "Logging",
}, {
Name: "stats_log_level",
Default: LogLevelInfo,
Help: "Log level to show --stats output DEBUG|INFO|NOTICE|ERROR",
Groups: "Logging",
}, {
Name: "bwlimit",
Default: BwTimetable{},
Help: "Bandwidth limit in KiB/s, or use suffix B|K|M|G|T|P or a full timetable",
Groups: "Networking",
}, {
Name: "bwlimit_file",
Default: BwTimetable{},
Help: "Bandwidth limit per file in KiB/s, or use suffix B|K|M|G|T|P or a full timetable",
Groups: "Networking",
}, {
Name: "buffer_size",
Default: SizeSuffix(16 << 20),
Help: "In memory buffer size when reading files for each --transfer",
Groups: "Performance",
}, {
Name: "streaming_upload_cutoff",
Default: SizeSuffix(100 * 1024),
Help: "Cutoff for switching to chunked upload if file size is unknown, upload starts after reaching cutoff or when file ends",
Groups: "Copy",
}, {
Name: "dump",
Default: DumpFlags(0),
Help: "List of items to dump from: " + DumpFlagsList,
Groups: "Debugging",
}, {
Name: "max_transfer",
Default: SizeSuffix(-1),
Help: "Maximum size of data to transfer",
Groups: "Copy",
}, {
Name: "max_duration",
Default: time.Duration(0),
Help: "Maximum duration rclone will transfer data for",
Groups: "Copy",
}, {
Name: "cutoff_mode",
Default: CutoffMode(0),
Help: "Mode to stop transfers when reaching the max transfer limit HARD|SOFT|CAUTIOUS",
Groups: "Copy",
}, {
Name: "max_backlog",
Default: 10000,
Help: "Maximum number of objects in sync or check backlog",
Groups: "Copy,Check",
}, {
Name: "max_stats_groups",
Default: 1000,
Help: "Maximum number of stats groups to keep in memory, on max oldest is discarded",
Groups: "Logging",
}, {
Name: "stats_one_line",
Default: false,
Help: "Make the stats fit on one line",
Groups: "Logging",
}, {
Name: "stats_one_line_date",
Default: false,
Help: "Enable --stats-one-line and add current date/time prefix",
Groups: "Logging",
}, {
Name: "stats_one_line_date_format",
Default: "",
Help: "Enable --stats-one-line-date and use custom formatted date: Enclose date string in double quotes (\"), see https://golang.org/pkg/time/#Time.Format",
Groups: "Logging",
}, {
Name: "error_on_no_transfer",
Default: false,
Help: "Sets exit code 9 if no files are transferred, useful in scripts",
Groups: "Config",
}, {
Name: "progress",
ShortOpt: "P",
Default: false,
Help: "Show progress during transfer",
Groups: "Logging",
}, {
Name: "progress_terminal_title",
Default: false,
Help: "Show progress on the terminal title (requires -P/--progress)",
Groups: "Logging",
}, {
Name: "use_cookies",
Default: false,
Help: "Enable session cookiejar",
Groups: "Networking",
}, {
Name: "use_mmap",
Default: false,
Help: "Use mmap allocator (see docs)",
Groups: "Config",
}, {
Name: "ca_cert",
Default: []string{},
Help: "CA certificate used to verify servers",
Groups: "Networking",
}, {
Name: "client_cert",
Default: "",
Help: "Client SSL certificate (PEM) for mutual TLS auth",
Groups: "Networking",
}, {
Name: "client_key",
Default: "",
Help: "Client SSL private key (PEM) for mutual TLS auth",
Groups: "Networking",
}, {
Name: "multi_thread_cutoff",
Default: SizeSuffix(256 * 1024 * 1024),
Help: "Use multi-thread downloads for files above this size",
Groups: "Copy",
}, {
Name: "multi_thread_streams",
Default: 4,
Help: "Number of streams to use for multi-thread downloads",
Groups: "Copy",
}, {
Name: "multi_thread_write_buffer_size",
Default: SizeSuffix(128 * 1024),
Help: "In memory buffer size for writing when in multi-thread mode",
Groups: "Copy",
}, {
Name: "multi_thread_chunk_size",
Default: SizeSuffix(64 * 1024 * 1024),
Help: "Chunk size for multi-thread downloads / uploads, if not set by filesystem",
Groups: "Copy",
}, {
Name: "use_json_log",
Default: false,
Help: "Use json log format",
Groups: "Logging",
}, {
Name: "order_by",
Default: "",
Help: "Instructions on how to order the transfers, e.g. 'size,descending'",
Groups: "Copy",
}, {
Name: "refresh_times",
Default: false,
Help: "Refresh the modtime of remote files",
Groups: "Copy",
}, {
Name: "no_console",
Default: false,
Help: "Hide console window (supported on Windows only)",
Groups: "Config",
}, {
Name: "fs_cache_expire_duration",
Default: 300 * time.Second,
Help: "Cache remotes for this long (0 to disable caching)",
Groups: "Config",
}, {
Name: "fs_cache_expire_interval",
Default: 60 * time.Second,
Help: "Interval to check for expired remotes",
Groups: "Config",
}, {
Name: "disable_http2",
Default: false,
Help: "Disable HTTP/2 in the global transport",
Groups: "Networking",
}, {
Name: "human_readable",
Default: false,
Help: "Print numbers in a human-readable format, sizes with suffix Ki|Mi|Gi|Ti|Pi",
Groups: "Config",
}, {
Name: "kv_lock_time",
Default: 1 * time.Second,
Help: "Maximum time to keep key-value database locked by process",
Groups: "Config",
}, {
Name: "disable_http_keep_alives",
Default: false,
Help: "Disable HTTP keep-alives and use each connection once.",
Groups: "Networking",
}, {
Name: "metadata",
ShortOpt: "M",
Default: false,
Help: "If set, preserve metadata when copying objects",
Groups: "Metadata,Copy",
}, {
Name: "server_side_across_configs",
Default: false,
Help: "Allow server-side operations (e.g. copy) to work across different configs",
Groups: "Copy",
}, {
Name: "color",
Default: TerminalColorMode(0),
Help: "When to show colors (and other ANSI codes) AUTO|NEVER|ALWAYS",
Groups: "Config",
}, {
Name: "default_time",
Default: Time(time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)),
Help: "Time to show if modtime is unknown for files and directories",
Groups: "Config,Listing",
}, {
Name: "inplace",
Default: false,
Help: "Download directly to destination file instead of atomic download to temp/rename",
Groups: "Copy",
}, {
Name: "metadata_mapper",
Default: SpaceSepList{},
Help: "Program to run to transforming metadata before upload",
Groups: "Metadata",
}, {
Name: "partial_suffix",
Default: ".partial",
Help: "Add partial-suffix to temporary file name when --inplace is not used",
Groups: "Copy",
}}
// ConfigInfo is filesystem config options
type ConfigInfo struct {
LogLevel LogLevel `config:"log_level"`
StatsLogLevel LogLevel `config:"stats_log_level"`
UseJSONLog bool `config:"use_json_log"`
DryRun bool `config:"dry_run"`
Interactive bool `config:"interactive"`
CheckSum bool `config:"checksum"`
SizeOnly bool `config:"size_only"`
IgnoreTimes bool `config:"ignore_times"`
IgnoreExisting bool `config:"ignore_existing"`
IgnoreErrors bool `config:"ignore_errors"`
ModifyWindow time.Duration `config:"modify_window"`
Checkers int `config:"checkers"`
Transfers int `config:"transfers"`
ConnectTimeout time.Duration `config:"contimeout"` // Connect timeout
Timeout time.Duration `config:"timeout"` // Data channel timeout
ExpectContinueTimeout time.Duration `config:"expect_continue_timeout"`
Dump DumpFlags `config:"dump"`
InsecureSkipVerify bool `config:"no_check_certificate"` // Skip server certificate verification
DeleteMode DeleteMode `config:"delete_mode"`
MaxDelete int64 `config:"max_delete"`
MaxDeleteSize SizeSuffix `config:"max_delete_size"`
TrackRenames bool `config:"track_renames"` // Track file renames.
TrackRenamesStrategy string `config:"track_renames_strategy"` // Comma separated list of strategies used to track renames
Retries int `config:"retries"` // High-level retries
RetriesInterval time.Duration `config:"retries_sleep"`
LowLevelRetries int `config:"low_level_retries"`
UpdateOlder bool `config:"update"` // Skip files that are newer on the destination
NoGzip bool `config:"no_gzip_encoding"` // Disable compression
MaxDepth int `config:"max_depth"`
IgnoreSize bool `config:"ignore_size"`
IgnoreChecksum bool `config:"ignore_checksum"`
IgnoreCaseSync bool `config:"ignore_case_sync"`
FixCase bool `config:"fix_case"`
NoTraverse bool `config:"no_traverse"`
CheckFirst bool `config:"check_first"`
NoCheckDest bool `config:"no_check_dest"`
NoUnicodeNormalization bool `config:"no_unicode_normalization"`
NoUpdateModTime bool `config:"no_update_modtime"`
NoUpdateDirModTime bool `config:"no_update_dir_modtime"`
DataRateUnit string `config:"stats_unit"`
CompareDest []string `config:"compare_dest"`
CopyDest []string `config:"copy_dest"`
BackupDir string `config:"backup_dir"`
Suffix string `config:"suffix"`
SuffixKeepExtension bool `config:"suffix_keep_extension"`
UseListR bool `config:"fast_list"`
BufferSize SizeSuffix `config:"buffer_size"`
BwLimit BwTimetable `config:"bwlimit"`
BwLimitFile BwTimetable `config:"bwlimit_file"`
TPSLimit float64 `config:"tpslimit"`
TPSLimitBurst int `config:"tpslimit_burst"`
BindAddr net.IP `config:"bind_addr"`
DisableFeatures []string `config:"disable"`
UserAgent string `config:"user_agent"`
Immutable bool `config:"immutable"`
AutoConfirm bool `config:"auto_confirm"`
StreamingUploadCutoff SizeSuffix `config:"streaming_upload_cutoff"`
StatsFileNameLength int `config:"stats_file_name_length"`
AskPassword bool `config:"ask_password"`
PasswordCommand SpaceSepList `config:"password_command"`
UseServerModTime bool `config:"use_server_modtime"`
MaxTransfer SizeSuffix `config:"max_transfer"`
MaxDuration time.Duration `config:"max_duration"`
CutoffMode CutoffMode `config:"cutoff_mode"`
MaxBacklog int `config:"max_backlog"`
MaxStatsGroups int `config:"max_stats_groups"`
StatsOneLine bool `config:"stats_one_line"`
StatsOneLineDate bool `config:"stats_one_line_date"` // If we want a date prefix at all
StatsOneLineDateFormat string `config:"stats_one_line_date_format"` // If we want to customize the prefix
ErrorOnNoTransfer bool `config:"error_on_no_transfer"` // Set appropriate exit code if no files transferred
Progress bool `config:"progress"`
ProgressTerminalTitle bool `config:"progress_terminal_title"`
Cookie bool `config:"use_cookies"`
UseMmap bool `config:"use_mmap"`
CaCert []string `config:"ca_cert"` // Client Side CA
ClientCert string `config:"client_cert"` // Client Side Cert
ClientKey string `config:"client_key"` // Client Side Key
MultiThreadCutoff SizeSuffix `config:"multi_thread_cutoff"`
MultiThreadStreams int `config:"multi_thread_streams"`
MultiThreadSet bool `config:"multi_thread_set"` // whether MultiThreadStreams was set (set in fs/config/configflags)
MultiThreadChunkSize SizeSuffix `config:"multi_thread_chunk_size"` // Chunk size for multi-thread downloads / uploads, if not set by filesystem
MultiThreadWriteBufferSize SizeSuffix `config:"multi_thread_write_buffer_size"`
OrderBy string `config:"order_by"` // instructions on how to order the transfer
UploadHeaders []*HTTPOption `config:"upload_headers"`
DownloadHeaders []*HTTPOption `config:"download_headers"`
Headers []*HTTPOption `config:"headers"`
MetadataSet Metadata `config:"metadata_set"` // extra metadata to write when uploading
RefreshTimes bool `config:"refresh_times"`
NoConsole bool `config:"no_console"`
TrafficClass uint8 `config:"traffic_class"`
FsCacheExpireDuration time.Duration `config:"fs_cache_expire_duration"`
FsCacheExpireInterval time.Duration `config:"fs_cache_expire_interval"`
DisableHTTP2 bool `config:"disable_http2"`
HumanReadable bool `config:"human_readable"`
KvLockTime time.Duration `config:"kv_lock_time"` // maximum time to keep key-value database locked by process
DisableHTTPKeepAlives bool `config:"disable_http_keep_alives"`
Metadata bool `config:"metadata"`
ServerSideAcrossConfigs bool `config:"server_side_across_configs"`
TerminalColorMode TerminalColorMode `config:"color"`
DefaultTime Time `config:"default_time"` // time that directories with no time should display
Inplace bool `config:"inplace"` // Download directly to destination file instead of atomic download to temp/rename
PartialSuffix string `config:"partial_suffix"`
MetadataMapper SpaceSepList `config:"metadata_mapper"`
}
func init() {
// Set any values which aren't the zero for the type
globalConfig.DeleteMode = DeleteModeDefault
// Register the config and fill globalConfig with the defaults
RegisterGlobalOptions(OptionsInfo{Name: "main", Opt: globalConfig, Options: ConfigOptionsInfo, Reload: globalConfig.Reload})
// initial guess at log level from the flags
globalConfig.LogLevel = initialLogLevel()
}
// Reload assumes the config has been edited and does what is necessary to make it live
func (ci *ConfigInfo) Reload(ctx context.Context) error {
// Set -vv if --dump is in use
if ci.Dump != 0 && ci.LogLevel != LogLevelDebug {
Logf(nil, "Automatically setting -vv as --dump is enabled")
ci.LogLevel = LogLevelDebug
}
// If --dry-run or -i then use NOTICE as minimum log level
if (ci.DryRun || ci.Interactive) && ci.StatsLogLevel > LogLevelNotice {
ci.StatsLogLevel = LogLevelNotice
}
// If --use-json-log then start the JSON logger
if ci.UseJSONLog {
InstallJSONLogger(ci.LogLevel)
}
// Check --compare-dest and --copy-dest
if len(ci.CompareDest) > 0 && len(ci.CopyDest) > 0 {
return fmt.Errorf("can't use --compare-dest with --copy-dest")
}
// Check --stats-one-line and dependent flags
switch {
case len(ci.StatsOneLineDateFormat) > 0:
ci.StatsOneLineDate = true
ci.StatsOneLine = true
case ci.StatsOneLineDate:
ci.StatsOneLineDateFormat = "2006/01/02 15:04:05 - "
ci.StatsOneLine = true
}
// Check --partial-suffix
if len(ci.PartialSuffix) > 16 {
return fmt.Errorf("--partial-suffix: Expecting suffix length not greater than %d but got %d", 16, len(ci.PartialSuffix))
}
// Make sure some values are > 0
nonZero := func(pi *int) {
if *pi <= 0 {
*pi = 1
}
}
// Check --stats-unit
if ci.DataRateUnit != "bits" && ci.DataRateUnit != "bytes" {
Errorf(nil, "Unknown unit %q passed to --stats-unit. Defaulting to bytes.", ci.DataRateUnit)
ci.DataRateUnit = "bytes"
}
// Check these are all > 0
nonZero(&ci.Retries)
nonZero(&ci.LowLevelRetries)
nonZero(&ci.Transfers)
nonZero(&ci.Checkers)
return nil
}
// Initial logging level
//
// Perform a simple check for debug flags to enable debug logging during the flag initialization
func initialLogLevel() LogLevel {
logLevel := LogLevelNotice
for argIndex, arg := range os.Args {
if strings.HasPrefix(arg, "-vv") && strings.TrimRight(arg, "v") == "-" {
logLevel = LogLevelDebug
}
if arg == "--log-level=DEBUG" || (arg == "--log-level" && len(os.Args) > argIndex+1 && os.Args[argIndex+1] == "DEBUG") {
logLevel = LogLevelDebug
}
if strings.HasPrefix(arg, "--verbose=") {
if level, err := strconv.Atoi(arg[10:]); err == nil && level >= 2 {
logLevel = LogLevelDebug
}
}
}
envValue, found := os.LookupEnv("RCLONE_LOG_LEVEL")
if found && envValue == "DEBUG" {
logLevel = LogLevelDebug
}
return logLevel
}
// TimeoutOrInfinite returns ci.Timeout if > 0 or infinite otherwise
func (ci *ConfigInfo) TimeoutOrInfinite() time.Duration {
if ci.Timeout > 0 {
return ci.Timeout
}
return ModTimeNotSupported
}
type configContextKeyType struct{}
// Context key for config
var configContextKey = configContextKeyType{}
// GetConfig returns the global or context sensitive context
func GetConfig(ctx context.Context) *ConfigInfo {
if ctx == nil {
return globalConfig
}
c := ctx.Value(configContextKey)
if c == nil {
return globalConfig
}
return c.(*ConfigInfo)
}
// CopyConfig copies the global config (if any) from srcCtx into
// dstCtx returning the new context.
func CopyConfig(dstCtx, srcCtx context.Context) context.Context {
if srcCtx == nil {
return dstCtx
}
c := srcCtx.Value(configContextKey)
if c == nil {
return dstCtx
}
return context.WithValue(dstCtx, configContextKey, c)
}
// AddConfig returns a mutable config structure based on a shallow
// copy of that found in ctx and returns a new context with that added
// to it.
func AddConfig(ctx context.Context) (context.Context, *ConfigInfo) {
c := GetConfig(ctx)
cCopy := new(ConfigInfo)
*cCopy = *c
newCtx := context.WithValue(ctx, configContextKey, cCopy)
return newCtx, cCopy
}
// ConfigToEnv converts a config section and name, e.g. ("my-remote",
// "ignore-size") into an environment name
// "RCLONE_CONFIG_MY-REMOTE_IGNORE_SIZE"
func ConfigToEnv(section, name string) string {
return "RCLONE_CONFIG_" + strings.ToUpper(section+"_"+strings.ReplaceAll(name, "-", "_"))
}
// OptionToEnv converts an option name, e.g. "ignore-size" into an
// environment name "RCLONE_IGNORE_SIZE"
func OptionToEnv(name string) string {
return "RCLONE_" + strings.ToUpper(strings.ReplaceAll(name, "-", "_"))
}