github.com/xhghs/rclone@v1.51.1-0.20200430155106-e186a28cced8/fs/config.go (about)

     1  package fs
     2  
     3  import (
     4  	"net"
     5  	"strings"
     6  	"time"
     7  
     8  	"github.com/pkg/errors"
     9  )
    10  
    11  // Global
    12  var (
    13  	// Config is the global config
    14  	Config = NewConfig()
    15  
    16  	// Read a value from the config file
    17  	//
    18  	// This is a function pointer to decouple the config
    19  	// implementation from the fs
    20  	ConfigFileGet = func(section, key string) (string, bool) { return "", false }
    21  
    22  	// Set a value into the config file and persist it
    23  	//
    24  	// This is a function pointer to decouple the config
    25  	// implementation from the fs
    26  	ConfigFileSet = func(section, key, value string) (err error) {
    27  		return errors.New("no config file set handler")
    28  	}
    29  
    30  	// CountError counts an error.  If any errors have been
    31  	// counted then it will exit with a non zero error code.
    32  	//
    33  	// This is a function pointer to decouple the config
    34  	// implementation from the fs
    35  	CountError = func(err error) error { return nil }
    36  
    37  	// ConfigProvider is the config key used for provider options
    38  	ConfigProvider = "provider"
    39  )
    40  
    41  // ConfigInfo is filesystem config options
    42  type ConfigInfo struct {
    43  	LogLevel               LogLevel
    44  	StatsLogLevel          LogLevel
    45  	UseJSONLog             bool
    46  	DryRun                 bool
    47  	CheckSum               bool
    48  	SizeOnly               bool
    49  	IgnoreTimes            bool
    50  	IgnoreExisting         bool
    51  	IgnoreErrors           bool
    52  	ModifyWindow           time.Duration
    53  	Checkers               int
    54  	Transfers              int
    55  	ConnectTimeout         time.Duration // Connect timeout
    56  	Timeout                time.Duration // Data channel timeout
    57  	ExpectContinueTimeout  time.Duration
    58  	Dump                   DumpFlags
    59  	InsecureSkipVerify     bool // Skip server certificate verification
    60  	DeleteMode             DeleteMode
    61  	MaxDelete              int64
    62  	TrackRenames           bool // Track file renames.
    63  	LowLevelRetries        int
    64  	UpdateOlder            bool // Skip files that are newer on the destination
    65  	NoGzip                 bool // Disable compression
    66  	MaxDepth               int
    67  	IgnoreSize             bool
    68  	IgnoreChecksum         bool
    69  	IgnoreCaseSync         bool
    70  	NoTraverse             bool
    71  	NoCheckDest            bool
    72  	NoUpdateModTime        bool
    73  	DataRateUnit           string
    74  	CompareDest            string
    75  	CopyDest               string
    76  	BackupDir              string
    77  	Suffix                 string
    78  	SuffixKeepExtension    bool
    79  	UseListR               bool
    80  	BufferSize             SizeSuffix
    81  	BwLimit                BwTimetable
    82  	TPSLimit               float64
    83  	TPSLimitBurst          int
    84  	BindAddr               net.IP
    85  	DisableFeatures        []string
    86  	UserAgent              string
    87  	Immutable              bool
    88  	AutoConfirm            bool
    89  	StreamingUploadCutoff  SizeSuffix
    90  	StatsFileNameLength    int
    91  	AskPassword            bool
    92  	PasswordCommand        SpaceSepList
    93  	UseServerModTime       bool
    94  	MaxTransfer            SizeSuffix
    95  	MaxDuration            time.Duration
    96  	MaxBacklog             int
    97  	MaxStatsGroups         int
    98  	StatsOneLine           bool
    99  	StatsOneLineDate       bool   // If we want a date prefix at all
   100  	StatsOneLineDateFormat string // If we want to customize the prefix
   101  	Progress               bool
   102  	Cookie                 bool
   103  	UseMmap                bool
   104  	CaCert                 string // Client Side CA
   105  	ClientCert             string // Client Side Cert
   106  	ClientKey              string // Client Side Key
   107  	MultiThreadCutoff      SizeSuffix
   108  	MultiThreadStreams     int
   109  	MultiThreadSet         bool   // whether MultiThreadStreams was set (set in fs/config/configflags)
   110  	OrderBy                string // instructions on how to order the transfer
   111  }
   112  
   113  // NewConfig creates a new config with everything set to the default
   114  // value.  These are the ultimate defaults and are overridden by the
   115  // config module.
   116  func NewConfig() *ConfigInfo {
   117  	c := new(ConfigInfo)
   118  
   119  	// Set any values which aren't the zero for the type
   120  	c.LogLevel = LogLevelNotice
   121  	c.StatsLogLevel = LogLevelInfo
   122  	c.ModifyWindow = time.Nanosecond
   123  	c.Checkers = 8
   124  	c.Transfers = 4
   125  	c.ConnectTimeout = 60 * time.Second
   126  	c.Timeout = 5 * 60 * time.Second
   127  	c.ExpectContinueTimeout = 1 * time.Second
   128  	c.DeleteMode = DeleteModeDefault
   129  	c.MaxDelete = -1
   130  	c.LowLevelRetries = 10
   131  	c.MaxDepth = -1
   132  	c.DataRateUnit = "bytes"
   133  	c.BufferSize = SizeSuffix(16 << 20)
   134  	c.UserAgent = "rclone/" + Version
   135  	c.StreamingUploadCutoff = SizeSuffix(100 * 1024)
   136  	c.MaxStatsGroups = 1000
   137  	c.StatsFileNameLength = 45
   138  	c.AskPassword = true
   139  	c.TPSLimitBurst = 1
   140  	c.MaxTransfer = -1
   141  	c.MaxBacklog = 10000
   142  	// We do not want to set the default here. We use this variable being empty as part of the fall-through of options.
   143  	//	c.StatsOneLineDateFormat = "2006/01/02 15:04:05 - "
   144  	c.MultiThreadCutoff = SizeSuffix(250 * 1024 * 1024)
   145  	c.MultiThreadStreams = 4
   146  
   147  	return c
   148  }
   149  
   150  // ConfigToEnv converts an config section and name, eg ("myremote",
   151  // "ignore-size") into an environment name
   152  // "RCLONE_CONFIG_MYREMOTE_IGNORE_SIZE"
   153  func ConfigToEnv(section, name string) string {
   154  	return "RCLONE_CONFIG_" + strings.ToUpper(strings.Replace(section+"_"+name, "-", "_", -1))
   155  }
   156  
   157  // OptionToEnv converts an option name, eg "ignore-size" into an
   158  // environment name "RCLONE_IGNORE_SIZE"
   159  func OptionToEnv(name string) string {
   160  	return "RCLONE_" + strings.ToUpper(strings.Replace(name, "-", "_", -1))
   161  }