Beispiel #1
0
func (e *environment) Load() error {
	locator := config.NewLocator()
	manager := config.NewManager(locator)

	config, err := manager.Load()

	if err != nil && os.IsNotExist(err) {
		e.dirty = true
		return nil
	}

	if err != nil {
		return err
	}

	loadedVersion := config.CsyncVersion()

	if loadedVersion.LT(e.version) {
		e.dirty = true
	}

	if loadedVersion.GT(e.version) {
		return errors.New(fmt.Sprintf(
			"config was written by newer csync version (%s vs. %s)", loadedVersion, e.version))
	}

	return nil
}
Beispiel #2
0
func (e *environment) Save() error {
	if !e.dirty {
		return nil
	}

	locator := config.NewLocator()
	manager := config.NewManager(locator)

	config := config.NewMutableConfig(e.Version())
	err := manager.Save(config)

	if err != nil {
		return err
	}

	e.dirty = false
	return nil
}