Esempio n. 1
0
func (f *JSONConfigFile) setUserConfigWithLock(u *UserConfig, overwrite bool) error {

	if u == nil {
		f.G().Log.Debug("| SetUserConfig(nil)")
		f.jw.DeleteKey("current_user")
		f.userConfigWrapper.userConfig = nil
		return f.flush()
	}

	parent := f.jw.AtKey("users")
	un := u.GetUsername()
	f.G().Log.Debug("| SetUserConfig(%s)", un)
	if parent.IsNil() {
		parent = jsonw.NewDictionary()
		f.jw.SetKey("users", parent)
		f.dirty = true
	}
	if parent.AtKey(un.String()).IsNil() || overwrite {
		uWrapper, err := jsonw.NewObjectWrapper(*u)
		if err != nil {
			return err
		}
		parent.SetKey(un.String(), uWrapper)
		f.userConfigWrapper.userConfig = u
		f.dirty = true
	}

	if !f.getCurrentUser().Eq(un) {
		f.jw.SetKey("current_user", jsonw.NewString(un.String()))
		f.userConfigWrapper.userConfig = nil
		f.dirty = true
	}

	return f.Write()
}
Esempio n. 2
0
func (d *Device) Export(lt LinkType) (*jsonw.Wrapper, error) {
	dw, err := jsonw.NewObjectWrapper(d)
	if err != nil {
		return nil, err
	}

	if lt == SubkeyType {
		// subkeys shouldn't have name or type
		if err := dw.DeleteKey("name"); err != nil {
			return nil, err
		}
		if err := dw.DeleteKey("type"); err != nil {
			return nil, err
		}
	}

	return dw, nil
}
Esempio n. 3
0
func (d *Device) Export(lt LinkType) (*jsonw.Wrapper, error) {
	dw, err := jsonw.NewObjectWrapper(d)
	if err != nil {
		return nil, err
	}

	if lt == SubkeyType {
		// subkeys shouldn't have name or type
		if err := dw.DeleteKey("name"); err != nil {
			return nil, err
		}
		if err := dw.DeleteKey("type"); err != nil {
			return nil, err
		}
	}

	// These were being set to 0, so don't include them
	dw.DeleteKey("mtime")
	dw.DeleteKey("ctime")

	return dw, nil
}