Merge pull request #2677 from nrm21/default_sync

Added STNODEFAULTFOLDER envvar to skip default folder creation
This commit is contained in:
Jakob Borg 2016-01-09 13:24:53 +01:00
commit 1e52cc474f
1 changed files with 43 additions and 28 deletions

View File

@ -146,6 +146,10 @@ Development Settings
The following environment variables modify syncthing's behavior in ways that The following environment variables modify syncthing's behavior in ways that
are mostly useful for developers. Use with care. are mostly useful for developers. Use with care.
STNODEFAULTFOLDER Don't create a default folder when starting for the first
time. This variable will be ignored anytime after the first
run.
STGUIASSETS Directory to load GUI assets from. Overrides compiled in STGUIASSETS Directory to load GUI assets from. Overrides compiled in
assets. assets.
@ -188,6 +192,7 @@ The following are valid values for the STTRACE variable:
var ( var (
noUpgrade = os.Getenv("STNOUPGRADE") != "" noUpgrade = os.Getenv("STNOUPGRADE") != ""
innerProcess = os.Getenv("STNORESTART") != "" || os.Getenv("STMONITORED") != "" innerProcess = os.Getenv("STNORESTART") != "" || os.Getenv("STMONITORED") != ""
noDefaultFolder = os.Getenv("STNODEFAULTFOLDER") != ""
) )
type RuntimeOptions struct { type RuntimeOptions struct {
@ -990,18 +995,28 @@ func setupGUI(mainService *suture.Supervisor, cfg *config.Wrapper, m *model.Mode
} }
func defaultConfig(myName string) config.Configuration { func defaultConfig(myName string) config.Configuration {
defaultFolder := config.NewFolderConfiguration("default", locations[locDefFolder]) var defaultFolder config.FolderConfiguration
if !noDefaultFolder {
l.Infoln("Default folder created and/or linked to new config")
defaultFolder = config.NewFolderConfiguration("default", locations[locDefFolder])
defaultFolder.RescanIntervalS = 60 defaultFolder.RescanIntervalS = 60
defaultFolder.MinDiskFreePct = 1 defaultFolder.MinDiskFreePct = 1
defaultFolder.Devices = []config.FolderDeviceConfiguration{{DeviceID: myID}} defaultFolder.Devices = []config.FolderDeviceConfiguration{{DeviceID: myID}}
defaultFolder.AutoNormalize = true defaultFolder.AutoNormalize = true
defaultFolder.MaxConflicts = -1 defaultFolder.MaxConflicts = -1
} else {
l.Infoln("We will skip creation of a default folder on first start since the proper envvar is set")
}
thisDevice := config.NewDeviceConfiguration(myID, myName) thisDevice := config.NewDeviceConfiguration(myID, myName)
thisDevice.Addresses = []string{"dynamic"} thisDevice.Addresses = []string{"dynamic"}
newCfg := config.New(myID) newCfg := config.New(myID)
if !noDefaultFolder {
newCfg.Folders = []config.FolderConfiguration{defaultFolder} newCfg.Folders = []config.FolderConfiguration{defaultFolder}
}
newCfg.Devices = []config.DeviceConfiguration{thisDevice} newCfg.Devices = []config.DeviceConfiguration{thisDevice}
port, err := getFreePort("127.0.0.1", 8384) port, err := getFreePort("127.0.0.1", 8384)