github.com/ncw/rclone@v1.48.1-0.20190724201158-a35aa1360e3e/fs/config.go (about)

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