|
@@ -65,7 +65,7 @@ func GenerateCertificate(certFile, keyFile string) (tls.Certificate, error) {
|
|
|
return tlsutil.NewCertificate(certFile, keyFile, tlsDefaultCommonName, deviceCertLifetimeDays)
|
|
return tlsutil.NewCertificate(certFile, keyFile, tlsDefaultCommonName, deviceCertLifetimeDays)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func DefaultConfig(path string, myID protocol.DeviceID, evLogger events.Logger, noDefaultFolder, skipPortProbing bool) (config.Wrapper, error) {
|
|
|
|
|
|
|
+func DefaultConfig(path string, myID protocol.DeviceID, evLogger events.Logger, skipPortProbing bool) (config.Wrapper, error) {
|
|
|
newCfg := config.New(myID)
|
|
newCfg := config.New(myID)
|
|
|
|
|
|
|
|
if skipPortProbing {
|
|
if skipPortProbing {
|
|
@@ -76,30 +76,18 @@ func DefaultConfig(path string, myID protocol.DeviceID, evLogger events.Logger,
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if noDefaultFolder {
|
|
|
|
|
- l.Infoln("We will skip creation of a default folder on first start")
|
|
|
|
|
- return config.Wrap(path, newCfg, myID, evLogger), nil
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- fcfg := newCfg.Defaults.Folder.Copy()
|
|
|
|
|
- fcfg.ID = "default"
|
|
|
|
|
- fcfg.Label = "Default Folder"
|
|
|
|
|
- fcfg.FilesystemType = config.FilesystemTypeBasic
|
|
|
|
|
- fcfg.Path = locations.Get(locations.DefFolder)
|
|
|
|
|
- newCfg.Folders = append(newCfg.Folders, fcfg)
|
|
|
|
|
- l.Infoln("Default folder created and/or linked to new config")
|
|
|
|
|
return config.Wrap(path, newCfg, myID, evLogger), nil
|
|
return config.Wrap(path, newCfg, myID, evLogger), nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// LoadConfigAtStartup loads an existing config. If it doesn't yet exist, it
|
|
// LoadConfigAtStartup loads an existing config. If it doesn't yet exist, it
|
|
|
-// creates a default one, without the default folder if noDefaultFolder is true.
|
|
|
|
|
-// Otherwise it checks the version, and archives and upgrades the config if
|
|
|
|
|
-// necessary or returns an error, if the version isn't compatible.
|
|
|
|
|
-func LoadConfigAtStartup(path string, cert tls.Certificate, evLogger events.Logger, allowNewerConfig, noDefaultFolder, skipPortProbing bool) (config.Wrapper, error) {
|
|
|
|
|
|
|
+// creates a default one. Otherwise it checks the version, and archives and
|
|
|
|
|
+// upgrades the config if necessary or returns an error, if the version
|
|
|
|
|
+// isn't compatible.
|
|
|
|
|
+func LoadConfigAtStartup(path string, cert tls.Certificate, evLogger events.Logger, allowNewerConfig, skipPortProbing bool) (config.Wrapper, error) {
|
|
|
myID := protocol.NewDeviceID(cert.Certificate[0])
|
|
myID := protocol.NewDeviceID(cert.Certificate[0])
|
|
|
cfg, originalVersion, err := config.Load(path, myID, evLogger)
|
|
cfg, originalVersion, err := config.Load(path, myID, evLogger)
|
|
|
if fs.IsNotExist(err) {
|
|
if fs.IsNotExist(err) {
|
|
|
- cfg, err = DefaultConfig(path, myID, evLogger, noDefaultFolder, skipPortProbing)
|
|
|
|
|
|
|
+ cfg, err = DefaultConfig(path, myID, evLogger, skipPortProbing)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, fmt.Errorf("failed to generate default config: %w", err)
|
|
return nil, fmt.Errorf("failed to generate default config: %w", err)
|
|
|
}
|
|
}
|