2014-03-15 17:06:11 +01:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
2020-11-05 12:33:32 +01:00
|
|
|
"context"
|
2021-11-04 11:12:57 +01:00
|
|
|
"errors"
|
2017-07-23 17:10:23 +02:00
|
|
|
"net"
|
2021-05-20 14:08:01 +02:00
|
|
|
"os"
|
2021-10-02 11:50:11 +02:00
|
|
|
"strconv"
|
2018-05-16 17:30:09 +02:00
|
|
|
"strings"
|
2014-03-15 17:06:11 +01:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Global
|
|
|
|
var (
|
2020-11-05 12:33:32 +01:00
|
|
|
// globalConfig for rclone
|
|
|
|
globalConfig = NewConfig()
|
2014-03-15 17:06:11 +01:00
|
|
|
|
2018-01-12 17:30:54 +01:00
|
|
|
// Read a value from the config file
|
|
|
|
//
|
|
|
|
// This is a function pointer to decouple the config
|
|
|
|
// implementation from the fs
|
2018-05-21 15:53:45 +02:00
|
|
|
ConfigFileGet = func(section, key string) (string, bool) { return "", false }
|
2017-01-03 03:52:41 +01:00
|
|
|
|
2019-08-14 18:06:13 +02:00
|
|
|
// Set a value into the config file and persist it
|
2018-05-14 19:06:57 +02:00
|
|
|
//
|
|
|
|
// This is a function pointer to decouple the config
|
|
|
|
// implementation from the fs
|
2019-08-14 18:06:13 +02:00
|
|
|
ConfigFileSet = func(section, key, value string) (err error) {
|
|
|
|
return errors.New("no config file set handler")
|
2018-05-14 19:06:57 +02:00
|
|
|
}
|
|
|
|
|
2022-09-12 21:43:53 +02:00
|
|
|
// 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 }
|
|
|
|
|
2018-01-12 17:30:54 +01:00
|
|
|
// CountError counts an error. If any errors have been
|
2020-12-30 11:37:14 +01:00
|
|
|
// counted then rclone will exit with a non zero error code.
|
2018-01-12 17:30:54 +01:00
|
|
|
//
|
|
|
|
// This is a function pointer to decouple the config
|
|
|
|
// implementation from the fs
|
2020-12-30 11:37:14 +01:00
|
|
|
CountError = func(err error) error { return err }
|
2018-04-13 17:06:37 +02:00
|
|
|
|
|
|
|
// ConfigProvider is the config key used for provider options
|
|
|
|
ConfigProvider = "provider"
|
2021-05-09 17:03:18 +02:00
|
|
|
|
|
|
|
// ConfigEdit is the config key used to show we wish to edit existing entries
|
|
|
|
ConfigEdit = "config_fs_edit"
|
2016-08-14 13:04:43 +02:00
|
|
|
)
|
|
|
|
|
2015-09-22 19:47:16 +02:00
|
|
|
// ConfigInfo is filesystem config options
|
2014-03-15 17:06:11 +01:00
|
|
|
type ConfigInfo struct {
|
2023-06-02 14:00:06 +02:00
|
|
|
LogLevel LogLevel
|
|
|
|
StatsLogLevel LogLevel
|
|
|
|
UseJSONLog bool
|
|
|
|
DryRun bool
|
|
|
|
Interactive bool
|
|
|
|
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
|
|
|
|
ExpectContinueTimeout time.Duration
|
|
|
|
Dump DumpFlags
|
|
|
|
InsecureSkipVerify bool // Skip server certificate verification
|
|
|
|
DeleteMode DeleteMode
|
|
|
|
MaxDelete int64
|
|
|
|
MaxDeleteSize SizeSuffix
|
2024-02-12 04:34:25 +01:00
|
|
|
TrackRenames bool // Track file renames.
|
|
|
|
TrackRenamesStrategy string // Comma separated list of strategies used to track renames
|
|
|
|
Retries int // High-level retries
|
|
|
|
RetriesInterval time.Duration // --retries-sleep
|
2023-06-02 14:00:06 +02:00
|
|
|
LowLevelRetries int
|
|
|
|
UpdateOlder bool // Skip files that are newer on the destination
|
|
|
|
NoGzip bool // Disable compression
|
|
|
|
MaxDepth int
|
|
|
|
IgnoreSize bool
|
|
|
|
IgnoreChecksum bool
|
|
|
|
IgnoreCaseSync bool
|
2023-10-09 04:59:22 +02:00
|
|
|
FixCase bool
|
2023-06-02 14:00:06 +02:00
|
|
|
NoTraverse bool
|
|
|
|
CheckFirst bool
|
|
|
|
NoCheckDest bool
|
|
|
|
NoUnicodeNormalization bool
|
|
|
|
NoUpdateModTime bool
|
2024-03-07 17:13:36 +01:00
|
|
|
NoUpdateDirModTime bool
|
2023-06-02 14:00:06 +02:00
|
|
|
DataRateUnit string
|
|
|
|
CompareDest []string
|
|
|
|
CopyDest []string
|
|
|
|
BackupDir string
|
|
|
|
Suffix string
|
|
|
|
SuffixKeepExtension bool
|
|
|
|
UseListR bool
|
|
|
|
BufferSize SizeSuffix
|
|
|
|
BwLimit BwTimetable
|
|
|
|
BwLimitFile BwTimetable
|
|
|
|
TPSLimit float64
|
|
|
|
TPSLimitBurst int
|
|
|
|
BindAddr net.IP
|
|
|
|
DisableFeatures []string
|
|
|
|
UserAgent string
|
|
|
|
Immutable bool
|
|
|
|
AutoConfirm bool
|
|
|
|
StreamingUploadCutoff SizeSuffix
|
|
|
|
StatsFileNameLength int
|
|
|
|
AskPassword bool
|
|
|
|
PasswordCommand SpaceSepList
|
|
|
|
UseServerModTime bool
|
|
|
|
MaxTransfer SizeSuffix
|
|
|
|
MaxDuration time.Duration
|
|
|
|
CutoffMode CutoffMode
|
|
|
|
MaxBacklog int
|
|
|
|
MaxStatsGroups int
|
|
|
|
StatsOneLine bool
|
|
|
|
StatsOneLineDate bool // If we want a date prefix at all
|
|
|
|
StatsOneLineDateFormat string // If we want to customize the prefix
|
|
|
|
ErrorOnNoTransfer bool // Set appropriate exit code if no files transferred
|
|
|
|
Progress bool
|
|
|
|
ProgressTerminalTitle bool
|
|
|
|
Cookie bool
|
|
|
|
UseMmap bool
|
|
|
|
CaCert []string // Client Side CA
|
|
|
|
ClientCert string // Client Side Cert
|
|
|
|
ClientKey string // Client Side Key
|
|
|
|
MultiThreadCutoff SizeSuffix
|
|
|
|
MultiThreadStreams int
|
2023-08-21 18:14:13 +02:00
|
|
|
MultiThreadSet bool // whether MultiThreadStreams was set (set in fs/config/configflags)
|
|
|
|
MultiThreadChunkSize SizeSuffix // Chunk size for multi-thread downloads / uploads, if not set by filesystem
|
|
|
|
MultiThreadWriteBufferSize SizeSuffix
|
2023-06-02 14:00:06 +02:00
|
|
|
OrderBy string // instructions on how to order the transfer
|
|
|
|
UploadHeaders []*HTTPOption
|
|
|
|
DownloadHeaders []*HTTPOption
|
|
|
|
Headers []*HTTPOption
|
|
|
|
MetadataSet Metadata // extra metadata to write when uploading
|
|
|
|
RefreshTimes bool
|
|
|
|
NoConsole bool
|
|
|
|
TrafficClass uint8
|
|
|
|
FsCacheExpireDuration time.Duration
|
|
|
|
FsCacheExpireInterval time.Duration
|
|
|
|
DisableHTTP2 bool
|
|
|
|
HumanReadable bool
|
|
|
|
KvLockTime time.Duration // maximum time to keep key-value database locked by process
|
|
|
|
DisableHTTPKeepAlives bool
|
|
|
|
Metadata bool
|
|
|
|
ServerSideAcrossConfigs bool
|
|
|
|
TerminalColorMode TerminalColorMode
|
2023-08-21 18:14:13 +02:00
|
|
|
DefaultTime Time // time that directories with no time should display
|
|
|
|
Inplace bool // Download directly to destination file instead of atomic download to temp/rename
|
2023-10-10 13:27:32 +02:00
|
|
|
PartialSuffix string
|
2023-10-24 00:47:18 +02:00
|
|
|
MetadataMapper SpaceSepList
|
2018-01-12 17:30:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewConfig creates a new config with everything set to the default
|
2019-04-30 14:06:24 +02:00
|
|
|
// value. These are the ultimate defaults and are overridden by the
|
2018-01-12 17:30:54 +01: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 15:00:46 +01:00
|
|
|
c.ExpectContinueTimeout = 1 * time.Second
|
2018-01-12 17:30:54 +01:00
|
|
|
c.DeleteMode = DeleteModeDefault
|
2018-01-22 19:53:18 +01:00
|
|
|
c.MaxDelete = -1
|
2022-08-03 16:53:02 +02:00
|
|
|
c.MaxDeleteSize = SizeSuffix(-1)
|
2024-02-12 04:34:25 +01:00
|
|
|
c.Retries = 3
|
2018-01-12 17:30:54 +01: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 17:45:07 +02:00
|
|
|
c.MaxStatsGroups = 1000
|
2019-01-14 17:12:39 +01:00
|
|
|
c.StatsFileNameLength = 45
|
2018-01-12 17:30:54 +01:00
|
|
|
c.AskPassword = true
|
|
|
|
c.TPSLimitBurst = 1
|
2018-04-21 23:03:27 +02:00
|
|
|
c.MaxTransfer = -1
|
2018-07-19 23:41:34 +02:00
|
|
|
c.MaxBacklog = 10000
|
2019-03-26 03:41:45 +01: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 - "
|
2023-08-21 18:14:13 +02:00
|
|
|
c.MultiThreadCutoff = SizeSuffix(256 * 1024 * 1024)
|
2019-04-24 18:04:40 +02:00
|
|
|
c.MultiThreadStreams = 4
|
2023-08-21 18:14:13 +02:00
|
|
|
c.MultiThreadChunkSize = SizeSuffix(64 * 1024 * 1024)
|
|
|
|
c.MultiThreadWriteBufferSize = SizeSuffix(128 * 1024)
|
2018-01-12 17:30:54 +01:00
|
|
|
|
2020-03-20 14:04:56 +01:00
|
|
|
c.TrackRenamesStrategy = "hash"
|
2021-03-29 18:18:49 +02:00
|
|
|
c.FsCacheExpireDuration = 300 * time.Second
|
|
|
|
c.FsCacheExpireInterval = 60 * time.Second
|
2021-10-12 13:57:54 +02:00
|
|
|
c.KvLockTime = 1 * time.Second
|
2023-05-03 11:39:42 +02:00
|
|
|
c.DefaultTime = Time(time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC))
|
2023-10-10 13:27:32 +02:00
|
|
|
c.PartialSuffix = ".partial"
|
2020-03-20 14:04:56 +01:00
|
|
|
|
2021-05-20 14:08:01 +02: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 11:50:11 +02:00
|
|
|
if strings.HasPrefix(arg, "--verbose=") {
|
|
|
|
if level, err := strconv.Atoi(arg[10:]); err == nil && level >= 2 {
|
|
|
|
c.LogLevel = LogLevelDebug
|
|
|
|
}
|
|
|
|
}
|
2021-05-20 14:08:01 +02:00
|
|
|
}
|
|
|
|
envValue, found := os.LookupEnv("RCLONE_LOG_LEVEL")
|
|
|
|
if found && envValue == "DEBUG" {
|
|
|
|
c.LogLevel = LogLevelDebug
|
|
|
|
}
|
|
|
|
|
2018-01-12 17:30:54 +01:00
|
|
|
return c
|
2015-05-10 12:25:54 +02:00
|
|
|
}
|
2018-05-16 17:30:09 +02:00
|
|
|
|
2021-03-01 13:05:36 +01: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 12:33:32 +01: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 14:13:54 +01: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 12:33:32 +01: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-16 19:39:46 +02:00
|
|
|
// ConfigToEnv converts a config section and name, e.g. ("my-remote",
|
2018-05-16 17:30:09 +02:00
|
|
|
// "ignore-size") into an environment name
|
2021-09-16 19:39:46 +02:00
|
|
|
// "RCLONE_CONFIG_MY-REMOTE_IGNORE_SIZE"
|
2018-05-16 17:30:09 +02:00
|
|
|
func ConfigToEnv(section, name string) string {
|
2022-05-16 18:11:45 +02:00
|
|
|
return "RCLONE_CONFIG_" + strings.ToUpper(section+"_"+strings.ReplaceAll(name, "-", "_"))
|
2018-05-16 17:30:09 +02:00
|
|
|
}
|
|
|
|
|
2020-10-13 23:49:58 +02:00
|
|
|
// OptionToEnv converts an option name, e.g. "ignore-size" into an
|
2018-05-16 17:30:09 +02:00
|
|
|
// environment name "RCLONE_IGNORE_SIZE"
|
|
|
|
func OptionToEnv(name string) string {
|
2022-05-16 18:11:45 +02:00
|
|
|
return "RCLONE_" + strings.ToUpper(strings.ReplaceAll(name, "-", "_"))
|
2018-05-16 17:30:09 +02:00
|
|
|
}
|