2014-03-15 16:06:11 +00:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
2017-07-23 15:10:23 +00:00
|
|
|
"net"
|
2018-05-16 15:30:09 +00:00
|
|
|
"strings"
|
2014-03-15 16:06:11 +00:00
|
|
|
"time"
|
2019-08-14 16:06:13 +00:00
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2014-03-15 16:06:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Global
|
|
|
|
var (
|
2015-09-22 17:47:16 +00:00
|
|
|
// Config is the global config
|
2018-01-12 16:30:54 +00:00
|
|
|
Config = NewConfig()
|
2014-03-15 16:06:11 +00:00
|
|
|
|
2018-01-12 16:30:54 +00:00
|
|
|
// Read a value from the config file
|
|
|
|
//
|
|
|
|
// This is a function pointer to decouple the config
|
|
|
|
// implementation from the fs
|
2018-05-21 13:53:45 +00:00
|
|
|
ConfigFileGet = func(section, key string) (string, bool) { return "", false }
|
2017-01-03 02:52:41 +00:00
|
|
|
|
2019-08-14 16:06:13 +00:00
|
|
|
// Set a value into the config file and persist it
|
2018-05-14 17:06:57 +00:00
|
|
|
//
|
|
|
|
// This is a function pointer to decouple the config
|
|
|
|
// implementation from the fs
|
2019-08-14 16:06:13 +00:00
|
|
|
ConfigFileSet = func(section, key, value string) (err error) {
|
|
|
|
return errors.New("no config file set handler")
|
2018-05-14 17:06:57 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 16:30:54 +00:00
|
|
|
// CountError counts an error. If any errors have been
|
|
|
|
// counted then it will exit with a non zero error code.
|
|
|
|
//
|
|
|
|
// This is a function pointer to decouple the config
|
|
|
|
// implementation from the fs
|
2019-11-18 14:13:02 +00:00
|
|
|
CountError = func(err error) error { return nil }
|
2018-04-13 15:06:37 +00:00
|
|
|
|
|
|
|
// ConfigProvider is the config key used for provider options
|
|
|
|
ConfigProvider = "provider"
|
2016-08-14 11:04:43 +00:00
|
|
|
)
|
|
|
|
|
2015-09-22 17:47:16 +00:00
|
|
|
// ConfigInfo is filesystem config options
|
2014-03-15 16:06:11 +00:00
|
|
|
type ConfigInfo struct {
|
2019-03-26 02:41:45 +00:00
|
|
|
LogLevel LogLevel
|
|
|
|
StatsLogLevel LogLevel
|
2019-07-26 00:54:09 +00:00
|
|
|
UseJSONLog bool
|
2019-03-26 02:41:45 +00:00
|
|
|
DryRun bool
|
2020-03-20 18:43:29 +00:00
|
|
|
Interactive bool
|
2019-03-26 02:41:45 +00:00
|
|
|
CheckSum bool
|
|
|
|
SizeOnly bool
|
|
|
|
IgnoreTimes bool
|
|
|
|
IgnoreExisting bool
|
|
|
|
IgnoreErrors bool
|
|
|
|
ModifyWindow time.Duration
|
|
|
|
Checkers int
|
|
|
|
Transfers int
|
|
|
|
ConnectTimeout time.Duration // Connect timeout
|
|
|
|
Timeout time.Duration // Data channel timeout
|
2020-01-09 14:00:46 +00:00
|
|
|
ExpectContinueTimeout time.Duration
|
2019-03-26 02:41:45 +00:00
|
|
|
Dump DumpFlags
|
|
|
|
InsecureSkipVerify bool // Skip server certificate verification
|
|
|
|
DeleteMode DeleteMode
|
|
|
|
MaxDelete int64
|
2020-03-20 13:04:56 +00:00
|
|
|
TrackRenames bool // Track file renames.
|
|
|
|
TrackRenamesStrategy string // Comma separated list of stratgies used to track renames
|
2019-03-26 02:41:45 +00:00
|
|
|
LowLevelRetries int
|
|
|
|
UpdateOlder bool // Skip files that are newer on the destination
|
|
|
|
NoGzip bool // Disable compression
|
|
|
|
MaxDepth int
|
|
|
|
IgnoreSize bool
|
|
|
|
IgnoreChecksum bool
|
2019-06-03 20:12:10 +00:00
|
|
|
IgnoreCaseSync bool
|
2019-03-26 02:41:45 +00:00
|
|
|
NoTraverse bool
|
2020-05-15 10:39:07 +00:00
|
|
|
CheckFirst bool
|
2019-10-17 16:41:11 +00:00
|
|
|
NoCheckDest bool
|
2020-05-14 23:27:59 +00:00
|
|
|
NoUnicodeNormalization bool
|
2019-03-26 02:41:45 +00:00
|
|
|
NoUpdateModTime bool
|
|
|
|
DataRateUnit string
|
2019-07-08 01:02:53 +00:00
|
|
|
CompareDest string
|
|
|
|
CopyDest string
|
2019-03-26 02:41:45 +00:00
|
|
|
BackupDir string
|
|
|
|
Suffix string
|
|
|
|
SuffixKeepExtension bool
|
|
|
|
UseListR bool
|
|
|
|
BufferSize SizeSuffix
|
|
|
|
BwLimit BwTimetable
|
|
|
|
TPSLimit float64
|
|
|
|
TPSLimitBurst int
|
|
|
|
BindAddr net.IP
|
|
|
|
DisableFeatures []string
|
|
|
|
UserAgent string
|
|
|
|
Immutable bool
|
|
|
|
AutoConfirm bool
|
|
|
|
StreamingUploadCutoff SizeSuffix
|
|
|
|
StatsFileNameLength int
|
|
|
|
AskPassword bool
|
2020-01-23 14:14:58 +00:00
|
|
|
PasswordCommand SpaceSepList
|
2019-03-26 02:41:45 +00:00
|
|
|
UseServerModTime bool
|
|
|
|
MaxTransfer SizeSuffix
|
2019-07-25 10:28:27 +00:00
|
|
|
MaxDuration time.Duration
|
2020-02-25 17:03:21 +00:00
|
|
|
CutoffMode CutoffMode
|
2019-03-26 02:41:45 +00:00
|
|
|
MaxBacklog int
|
2019-07-23 15:45:07 +00:00
|
|
|
MaxStatsGroups int
|
2019-03-26 02:41:45 +00:00
|
|
|
StatsOneLine bool
|
|
|
|
StatsOneLineDate bool // If we want a date prefix at all
|
|
|
|
StatsOneLineDateFormat string // If we want to customize the prefix
|
2019-12-18 11:52:20 +00:00
|
|
|
ErrorOnNoTransfer bool // Set appropriate exit code if no files transferred
|
2019-03-26 02:41:45 +00:00
|
|
|
Progress bool
|
|
|
|
Cookie bool
|
|
|
|
UseMmap bool
|
|
|
|
CaCert string // Client Side CA
|
|
|
|
ClientCert string // Client Side Cert
|
|
|
|
ClientKey string // Client Side Key
|
2019-04-24 16:04:40 +00:00
|
|
|
MultiThreadCutoff SizeSuffix
|
|
|
|
MultiThreadStreams int
|
2019-11-28 17:01:21 +00:00
|
|
|
MultiThreadSet bool // whether MultiThreadStreams was set (set in fs/config/configflags)
|
|
|
|
OrderBy string // instructions on how to order the transfer
|
2020-02-10 07:50:08 +00:00
|
|
|
UploadHeaders []*HTTPOption
|
|
|
|
DownloadHeaders []*HTTPOption
|
2020-04-23 14:24:21 +00:00
|
|
|
Headers []*HTTPOption
|
2020-06-16 15:24:54 +00:00
|
|
|
RefreshTimes bool
|
2018-01-12 16:30:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewConfig creates a new config with everything set to the default
|
2019-04-30 12:06:24 +00:00
|
|
|
// value. These are the ultimate defaults and are overridden by the
|
2018-01-12 16:30:54 +00:00
|
|
|
// config module.
|
|
|
|
func NewConfig() *ConfigInfo {
|
|
|
|
c := new(ConfigInfo)
|
|
|
|
|
|
|
|
// Set any values which aren't the zero for the type
|
|
|
|
c.LogLevel = LogLevelNotice
|
|
|
|
c.StatsLogLevel = LogLevelInfo
|
|
|
|
c.ModifyWindow = time.Nanosecond
|
|
|
|
c.Checkers = 8
|
|
|
|
c.Transfers = 4
|
|
|
|
c.ConnectTimeout = 60 * time.Second
|
|
|
|
c.Timeout = 5 * 60 * time.Second
|
2020-01-09 14:00:46 +00:00
|
|
|
c.ExpectContinueTimeout = 1 * time.Second
|
2018-01-12 16:30:54 +00:00
|
|
|
c.DeleteMode = DeleteModeDefault
|
2018-01-22 18:53:18 +00:00
|
|
|
c.MaxDelete = -1
|
2018-01-12 16:30:54 +00:00
|
|
|
c.LowLevelRetries = 10
|
|
|
|
c.MaxDepth = -1
|
|
|
|
c.DataRateUnit = "bytes"
|
|
|
|
c.BufferSize = SizeSuffix(16 << 20)
|
|
|
|
c.UserAgent = "rclone/" + Version
|
|
|
|
c.StreamingUploadCutoff = SizeSuffix(100 * 1024)
|
2019-07-23 15:45:07 +00:00
|
|
|
c.MaxStatsGroups = 1000
|
2019-01-14 16:12:39 +00:00
|
|
|
c.StatsFileNameLength = 45
|
2018-01-12 16:30:54 +00:00
|
|
|
c.AskPassword = true
|
|
|
|
c.TPSLimitBurst = 1
|
2018-04-21 21:03:27 +00:00
|
|
|
c.MaxTransfer = -1
|
2018-07-19 21:41:34 +00:00
|
|
|
c.MaxBacklog = 10000
|
2019-03-26 02:41:45 +00:00
|
|
|
// We do not want to set the default here. We use this variable being empty as part of the fall-through of options.
|
|
|
|
// c.StatsOneLineDateFormat = "2006/01/02 15:04:05 - "
|
2019-04-24 16:04:40 +00:00
|
|
|
c.MultiThreadCutoff = SizeSuffix(250 * 1024 * 1024)
|
|
|
|
c.MultiThreadStreams = 4
|
2018-01-12 16:30:54 +00:00
|
|
|
|
2020-03-20 13:04:56 +00:00
|
|
|
c.TrackRenamesStrategy = "hash"
|
|
|
|
|
2018-01-12 16:30:54 +00:00
|
|
|
return c
|
2015-05-10 10:25:54 +00:00
|
|
|
}
|
2018-05-16 15:30:09 +00:00
|
|
|
|
2020-05-20 10:39:20 +00:00
|
|
|
// ConfigToEnv converts a config section and name, eg ("myremote",
|
2018-05-16 15:30:09 +00:00
|
|
|
// "ignore-size") into an environment name
|
|
|
|
// "RCLONE_CONFIG_MYREMOTE_IGNORE_SIZE"
|
|
|
|
func ConfigToEnv(section, name string) string {
|
|
|
|
return "RCLONE_CONFIG_" + strings.ToUpper(strings.Replace(section+"_"+name, "-", "_", -1))
|
|
|
|
}
|
|
|
|
|
|
|
|
// OptionToEnv converts an option name, eg "ignore-size" into an
|
|
|
|
// environment name "RCLONE_IGNORE_SIZE"
|
|
|
|
func OptionToEnv(name string) string {
|
|
|
|
return "RCLONE_" + strings.ToUpper(strings.Replace(name, "-", "_", -1))
|
|
|
|
}
|