2014-03-16 00:06:11 +08:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
2020-11-05 19:33:32 +08:00
|
|
|
"context"
|
2021-11-04 18:12:57 +08:00
|
|
|
"errors"
|
2017-07-23 23:10:23 +08:00
|
|
|
"net"
|
2021-05-20 20:08:01 +08:00
|
|
|
"os"
|
2021-10-02 17:50:11 +08:00
|
|
|
"strconv"
|
2018-05-16 23:30:09 +08:00
|
|
|
"strings"
|
2014-03-16 00:06:11 +08:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Global
|
|
|
|
var (
|
2020-11-05 19:33:32 +08:00
|
|
|
// globalConfig for rclone
|
|
|
|
globalConfig = NewConfig()
|
2014-03-16 00:06:11 +08:00
|
|
|
|
2018-01-13 00:30:54 +08:00
|
|
|
// Read a value from the config file
|
|
|
|
//
|
|
|
|
// This is a function pointer to decouple the config
|
|
|
|
// implementation from the fs
|
2018-05-21 21:53:45 +08:00
|
|
|
ConfigFileGet = func(section, key string) (string, bool) { return "", false }
|
2017-01-03 10:52:41 +08:00
|
|
|
|
2019-08-15 00:06:13 +08:00
|
|
|
// Set a value into the config file and persist it
|
2018-05-15 01:06:57 +08:00
|
|
|
//
|
|
|
|
// This is a function pointer to decouple the config
|
|
|
|
// implementation from the fs
|
2019-08-15 00:06:13 +08:00
|
|
|
ConfigFileSet = func(section, key, value string) (err error) {
|
|
|
|
return errors.New("no config file set handler")
|
2018-05-15 01:06:57 +08:00
|
|
|
}
|
|
|
|
|
2018-01-13 00:30:54 +08:00
|
|
|
// CountError counts an error. If any errors have been
|
2020-12-30 18:37:14 +08:00
|
|
|
// counted then rclone will exit with a non zero error code.
|
2018-01-13 00:30:54 +08:00
|
|
|
//
|
|
|
|
// This is a function pointer to decouple the config
|
|
|
|
// implementation from the fs
|
2020-12-30 18:37:14 +08:00
|
|
|
CountError = func(err error) error { return err }
|
2018-04-13 23:06:37 +08:00
|
|
|
|
|
|
|
// ConfigProvider is the config key used for provider options
|
|
|
|
ConfigProvider = "provider"
|
2021-05-09 23:03:18 +08:00
|
|
|
|
|
|
|
// ConfigEdit is the config key used to show we wish to edit existing entries
|
|
|
|
ConfigEdit = "config_fs_edit"
|
2016-08-14 19:04:43 +08:00
|
|
|
)
|
|
|
|
|
2015-09-23 01:47:16 +08:00
|
|
|
// ConfigInfo is filesystem config options
|
2014-03-16 00:06:11 +08:00
|
|
|
type ConfigInfo struct {
|
2019-03-26 10:41:45 +08:00
|
|
|
LogLevel LogLevel
|
|
|
|
StatsLogLevel LogLevel
|
2019-07-26 08:54:09 +08:00
|
|
|
UseJSONLog bool
|
2019-03-26 10:41:45 +08:00
|
|
|
DryRun bool
|
2020-03-21 02:43:29 +08:00
|
|
|
Interactive bool
|
2019-03-26 10:41:45 +08: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 22:00:46 +08:00
|
|
|
ExpectContinueTimeout time.Duration
|
2019-03-26 10:41:45 +08:00
|
|
|
Dump DumpFlags
|
|
|
|
InsecureSkipVerify bool // Skip server certificate verification
|
|
|
|
DeleteMode DeleteMode
|
|
|
|
MaxDelete int64
|
2020-03-20 21:04:56 +08:00
|
|
|
TrackRenames bool // Track file renames.
|
Spelling fixes
Fix spelling of: above, already, anonymous, associated,
authentication, bandwidth, because, between, blocks, calculate,
candidates, cautious, changelog, cleaner, clipboard, command,
completely, concurrently, considered, constructs, corrupt, current,
daemon, dependencies, deprecated, directory, dispatcher, download,
eligible, ellipsis, encrypter, endpoint, entrieslist, essentially,
existing writers, existing, expires, filesystem, flushing, frequently,
hierarchy, however, implementation, implements, inaccurate,
individually, insensitive, longer, maximum, metadata, modified,
multipart, namedirfirst, nextcloud, obscured, opened, optional,
owncloud, pacific, passphrase, password, permanently, persimmon,
positive, potato, protocol, quota, receiving, recommends, referring,
requires, revisited, satisfied, satisfies, satisfy, semver,
serialized, session, storage, strategies, stringlist, successful,
supported, surprise, temporarily, temporary, transactions, unneeded,
update, uploads, wrapped
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2020-10-09 08:17:24 +08:00
|
|
|
TrackRenamesStrategy string // Comma separated list of strategies used to track renames
|
2019-03-26 10:41:45 +08: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-04 04:12:10 +08:00
|
|
|
IgnoreCaseSync bool
|
2019-03-26 10:41:45 +08:00
|
|
|
NoTraverse bool
|
2020-05-15 18:39:07 +08:00
|
|
|
CheckFirst bool
|
2019-10-18 00:41:11 +08:00
|
|
|
NoCheckDest bool
|
2020-05-15 07:27:59 +08:00
|
|
|
NoUnicodeNormalization bool
|
2019-03-26 10:41:45 +08:00
|
|
|
NoUpdateModTime bool
|
|
|
|
DataRateUnit string
|
2020-11-16 11:04:29 +08:00
|
|
|
CompareDest []string
|
|
|
|
CopyDest []string
|
2019-03-26 10:41:45 +08:00
|
|
|
BackupDir string
|
|
|
|
Suffix string
|
|
|
|
SuffixKeepExtension bool
|
|
|
|
UseListR bool
|
|
|
|
BufferSize SizeSuffix
|
|
|
|
BwLimit BwTimetable
|
2020-06-20 23:10:02 +08:00
|
|
|
BwLimitFile BwTimetable
|
2019-03-26 10:41:45 +08:00
|
|
|
TPSLimit float64
|
|
|
|
TPSLimitBurst int
|
|
|
|
BindAddr net.IP
|
|
|
|
DisableFeatures []string
|
|
|
|
UserAgent string
|
|
|
|
Immutable bool
|
|
|
|
AutoConfirm bool
|
|
|
|
StreamingUploadCutoff SizeSuffix
|
|
|
|
StatsFileNameLength int
|
|
|
|
AskPassword bool
|
2020-01-23 22:14:58 +08:00
|
|
|
PasswordCommand SpaceSepList
|
2019-03-26 10:41:45 +08:00
|
|
|
UseServerModTime bool
|
|
|
|
MaxTransfer SizeSuffix
|
2019-07-25 18:28:27 +08:00
|
|
|
MaxDuration time.Duration
|
2020-02-26 01:03:21 +08:00
|
|
|
CutoffMode CutoffMode
|
2019-03-26 10:41:45 +08:00
|
|
|
MaxBacklog int
|
2019-07-23 23:45:07 +08:00
|
|
|
MaxStatsGroups int
|
2019-03-26 10:41:45 +08: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 19:52:20 +08:00
|
|
|
ErrorOnNoTransfer bool // Set appropriate exit code if no files transferred
|
2019-03-26 10:41:45 +08:00
|
|
|
Progress bool
|
2020-10-06 23:34:26 +08:00
|
|
|
ProgressTerminalTitle bool
|
2019-03-26 10:41:45 +08:00
|
|
|
Cookie bool
|
|
|
|
UseMmap bool
|
|
|
|
CaCert string // Client Side CA
|
|
|
|
ClientCert string // Client Side Cert
|
|
|
|
ClientKey string // Client Side Key
|
2019-04-25 00:04:40 +08:00
|
|
|
MultiThreadCutoff SizeSuffix
|
|
|
|
MultiThreadStreams int
|
2019-11-29 01:01:21 +08:00
|
|
|
MultiThreadSet bool // whether MultiThreadStreams was set (set in fs/config/configflags)
|
|
|
|
OrderBy string // instructions on how to order the transfer
|
2020-02-10 15:50:08 +08:00
|
|
|
UploadHeaders []*HTTPOption
|
|
|
|
DownloadHeaders []*HTTPOption
|
2020-04-23 22:24:21 +08:00
|
|
|
Headers []*HTTPOption
|
2020-06-16 23:24:54 +08:00
|
|
|
RefreshTimes bool
|
2021-01-24 19:28:39 +08:00
|
|
|
NoConsole bool
|
2021-01-29 11:41:50 +08:00
|
|
|
TrafficClass uint8
|
2021-03-30 00:18:49 +08:00
|
|
|
FsCacheExpireDuration time.Duration
|
|
|
|
FsCacheExpireInterval time.Duration
|
2021-04-20 00:00:07 +08:00
|
|
|
DisableHTTP2 bool
|
2021-04-02 22:11:21 +08:00
|
|
|
HumanReadable bool
|
2021-10-12 19:57:54 +08:00
|
|
|
KvLockTime time.Duration // maximum time to keep key-value database locked by process
|
2018-01-13 00:30:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewConfig creates a new config with everything set to the default
|
2019-04-30 20:06:24 +08:00
|
|
|
// value. These are the ultimate defaults and are overridden by the
|
2018-01-13 00:30:54 +08: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 22:00:46 +08:00
|
|
|
c.ExpectContinueTimeout = 1 * time.Second
|
2018-01-13 00:30:54 +08:00
|
|
|
c.DeleteMode = DeleteModeDefault
|
2018-01-23 02:53:18 +08:00
|
|
|
c.MaxDelete = -1
|
2018-01-13 00:30:54 +08: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 23:45:07 +08:00
|
|
|
c.MaxStatsGroups = 1000
|
2019-01-15 00:12:39 +08:00
|
|
|
c.StatsFileNameLength = 45
|
2018-01-13 00:30:54 +08:00
|
|
|
c.AskPassword = true
|
|
|
|
c.TPSLimitBurst = 1
|
2018-04-22 05:03:27 +08:00
|
|
|
c.MaxTransfer = -1
|
2018-07-20 05:41:34 +08:00
|
|
|
c.MaxBacklog = 10000
|
2019-03-26 10:41:45 +08: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-25 00:04:40 +08:00
|
|
|
c.MultiThreadCutoff = SizeSuffix(250 * 1024 * 1024)
|
|
|
|
c.MultiThreadStreams = 4
|
2018-01-13 00:30:54 +08:00
|
|
|
|
2020-03-20 21:04:56 +08:00
|
|
|
c.TrackRenamesStrategy = "hash"
|
2021-03-30 00:18:49 +08:00
|
|
|
c.FsCacheExpireDuration = 300 * time.Second
|
|
|
|
c.FsCacheExpireInterval = 60 * time.Second
|
2021-10-12 19:57:54 +08:00
|
|
|
c.KvLockTime = 1 * time.Second
|
2020-03-20 21:04:56 +08:00
|
|
|
|
2021-05-20 20:08:01 +08:00
|
|
|
// Perform a simple check for debug flags to enable debug logging during the flag initialization
|
|
|
|
for argIndex, arg := range os.Args {
|
|
|
|
if strings.HasPrefix(arg, "-vv") && strings.TrimRight(arg, "v") == "-" {
|
|
|
|
c.LogLevel = LogLevelDebug
|
|
|
|
}
|
|
|
|
if arg == "--log-level=DEBUG" || (arg == "--log-level" && len(os.Args) > argIndex+1 && os.Args[argIndex+1] == "DEBUG") {
|
|
|
|
c.LogLevel = LogLevelDebug
|
|
|
|
}
|
2021-10-02 17:50:11 +08:00
|
|
|
if strings.HasPrefix(arg, "--verbose=") {
|
|
|
|
if level, err := strconv.Atoi(arg[10:]); err == nil && level >= 2 {
|
|
|
|
c.LogLevel = LogLevelDebug
|
|
|
|
}
|
|
|
|
}
|
2021-05-20 20:08:01 +08:00
|
|
|
}
|
|
|
|
envValue, found := os.LookupEnv("RCLONE_LOG_LEVEL")
|
|
|
|
if found && envValue == "DEBUG" {
|
|
|
|
c.LogLevel = LogLevelDebug
|
|
|
|
}
|
|
|
|
|
2018-01-13 00:30:54 +08:00
|
|
|
return c
|
2015-05-10 18:25:54 +08:00
|
|
|
}
|
2018-05-16 23:30:09 +08:00
|
|
|
|
2021-03-01 20:05:36 +08:00
|
|
|
// TimeoutOrInfinite returns ci.Timeout if > 0 or infinite otherwise
|
|
|
|
func (c *ConfigInfo) TimeoutOrInfinite() time.Duration {
|
|
|
|
if c.Timeout > 0 {
|
|
|
|
return c.Timeout
|
|
|
|
}
|
|
|
|
return ModTimeNotSupported
|
|
|
|
}
|
|
|
|
|
2020-11-05 19:33:32 +08:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2021-02-19 21:13:54 +08:00
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
2020-11-05 19:33:32 +08:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2021-09-17 01:39:46 +08:00
|
|
|
// ConfigToEnv converts a config section and name, e.g. ("my-remote",
|
2018-05-16 23:30:09 +08:00
|
|
|
// "ignore-size") into an environment name
|
2021-09-17 01:39:46 +08:00
|
|
|
// "RCLONE_CONFIG_MY-REMOTE_IGNORE_SIZE"
|
2018-05-16 23:30:09 +08:00
|
|
|
func ConfigToEnv(section, name string) string {
|
2021-09-17 01:39:46 +08:00
|
|
|
return "RCLONE_CONFIG_" + strings.ToUpper(section+"_"+strings.Replace(name, "-", "_", -1))
|
2018-05-16 23:30:09 +08:00
|
|
|
}
|
|
|
|
|
2020-10-14 05:49:58 +08:00
|
|
|
// OptionToEnv converts an option name, e.g. "ignore-size" into an
|
2018-05-16 23:30:09 +08:00
|
|
|
// environment name "RCLONE_IGNORE_SIZE"
|
|
|
|
func OptionToEnv(name string) string {
|
|
|
|
return "RCLONE_" + strings.ToUpper(strings.Replace(name, "-", "_", -1))
|
|
|
|
}
|