// Save saves the config
428903
func (c *Config) Save() error {
	if err := c.checkDefaults(); err != nil {
		return err
	}

	buf, err := yaml.Marshal(c)
	if err != nil {
		return errors.Wrapf(err, "failed to marshal YAML")
	}

	cfgLoc := configLocation()
	cfgDir := filepath.Dir(cfgLoc)
	if !fsutil.IsDir(cfgDir) {
		if err := os.MkdirAll(cfgDir, 0700); err != nil {
			return errors.Wrapf(err, "failed to create dir '%s'", cfgDir)
		}
	}
	if err := ioutil.WriteFile(cfgLoc, buf, 0600); err != nil {
		return errors.Wrapf(err, "failed to write config file to '%s'", cfgLoc)
	}
	if debug {
		fmt.Printf("[DEBUG] Saved config to %s: %+v\n", cfgLoc, c)
	}
	return nil
}
410778
func (s *Store) Save(dir string) error {
	s.RLock()
	defer s.RUnlock()

	dir = strings.TrimRight(dir, "/")
	for name, g := range s.groups {
		path := fmt.Sprintf("%s/%s", dir, strings.Replace(name, "/", "_", -1)+entityFileSuffix)
		f, err := os.Create(path)
		if err != nil {
			return err
		}
		defer f.Close()

		for _, entities := range g.entities {
			for _, e := range entities {
				f.WriteString(string(e) + "\n")
			}
		}
		f.Close()
	}
	return nil
}
745985
func Save(env *Environment) error {
	for _, r := range registered {
		if r.Condition() {
			return r.DAO.Save(env)
		}
	}
	return fmt.Errorf("no environment DAO found")
}
1222088
func (target *AMQPTarget) Save(eventData event.Event) error {
	return target.send(eventData)
}
503243
func (s *RediStore) save(session *sessions.Session) error {
	b, err := s.serializer.Serialize(session)
	if err != nil {
		return err
	}
	if s.maxLength != 0 && len(b) > s.maxLength {
		return errors.New("SessionStore: the value to store is too big")
	}
	conn := s.Pool.Get()
	defer conn.Close()
	if err = conn.Err(); err != nil {
		return err
	}
	age := session.Options.MaxAge
	if age == 0 {
		age = s.DefaultMaxAge
	}
	_, err = conn.Do("SETEX", s.keyPrefix+session.ID, age, b)
	return err
}
400291
func (dao *WindowsDAO) Save(env *Environment) error {
	key, err := registry.OpenKey(registry.CURRENT_USER, "Environment", registry.ALL_ACCESS)
	if err != nil {
		return err
	}
	defer key.Close()

	ki, err := key.Stat()
	if err != nil {
		return err
	}

	names, err := key.ReadValueNames(int(ki.ValueCount))
	if err != nil {
		return err
	}

	for i := range env.Setters {
		env.Setters[i].Value = strings.Replace(env.Setters[i].Value, "/", "\\", -1)
	}
	for i := range env.Appenders {
		env.Appenders[i].Value = strings.Replace(env.Appenders[i].Value, "/", "\\", -1)
	}

	// set
set_loop:
	for _, nv := range env.Setters {
		for _, name := range names {
			if strings.ToUpper(name) == strings.ToUpper(nv.Name) {
				value, _, err := key.GetStringValue(name)
				if err != nil {
					return err
				}
				if value == nv.Value {
					continue set_loop
				}
			}
		}
		err = key.SetStringValue(nv.Name, nv.Value)
		if err != nil {
			return err
		}
	}

	// append
append_loop:
	for _, nv := range env.Appenders {
		values := []string{}
		for _, name := range names {
			if strings.ToUpper(name) == strings.ToUpper(nv.Name) {
				value, _, err := key.GetStringValue(name)
				if err != nil {
					return err
				}
				values = append(values, strings.Split(value, ";")...)
				values = uniquei(append(values, nv.Value))
				err = key.SetStringValue(nv.Name, strings.Join(values, ";"))
				if err != nil {
					return err
				}
				break append_loop
			}
		}
		err = key.SetStringValue(nv.Name, nv.Value)
		if err != nil {
			return err
		}
	}

	// unset
	for _, name := range names {
		for _, nv := range env.Unsetters {
			if nv.Name == name {
				err = key.DeleteValue(name)
				if err != nil {
					return err
				}
			}
		}
	}

	str := "Environment"
	pstr, _ := syscall.UTF16PtrFromString(str)
	sendMessageTimeout(win.HWND_BROADCAST, win.WM_WININICHANGE, 0, uintptr(unsafe.Pointer(pstr)), SMTO_BLOCK, 5000, 0)

	return nil
}
496223
func (s shareDBV1) Save(filename string) *probe.Error {
	s.mutex.Lock()
	defer s.mutex.Unlock()

	return s.save(filename)
}
97339
func Save(st ImageMetadataInterface, metadata params.MetadataSaveParams) ([]params.ErrorResult, error) {
	all := make([]params.ErrorResult, len(metadata.Metadata))
	if len(metadata.Metadata) == 0 {
		return nil, nil
	}
	modelCfg, err := st.ModelConfig()
	if err != nil {
		return nil, errors.Annotatef(err, "getting model config")
	}
	for i, one := range metadata.Metadata {
		md := ParseMetadataListFromParams(one, modelCfg)
		err := st.SaveMetadata(md)
		all[i] = params.ErrorResult{Error: common.ServerError(err)}
	}
	return all, nil
}
389025
func (target *KafkaTarget) Save(eventData event.Event) error {
	return target.send(eventData)
}
1279761
func (target *RedisTarget) Save(eventData event.Event) error {
	return target.send(eventData)
}
629950
func (d *DirPreferences) Save() error {
	f, err := os.Create(d.Path)
	if err != nil {
		return err
	}

	defer f.Close()

	enc := json.NewEncoder(f)
	return enc.Encode(d)
}
1209431
func saveConfigs(configModel ConfigsModel) error {
	if err := ensureEnvmanConfigDirExists(); err != nil {
		return err
	}

	bytes, err := json.Marshal(configModel)
	if err != nil {
		return err
	}
	configsPth := getEnvmanConfigsFilePath()
	return fileutil.WriteBytesToFile(configsPth, bytes)
}
835061
func saveConfig(c Config) {
	j, err := json.MarshalIndent(c, "", "  ")
	if err == nil {
		err = ioutil.WriteFile(configFile, j, 0644)
	}

	if err != nil {
		log.Fatal(err)
	}
}
586946
func (s *Registry) Save(w http.ResponseWriter) error {
	var errMulti MultiError
	for name, info := range s.sessions {
		session := info.s
		if session.store == nil {
			errMulti = append(errMulti, fmt.Errorf(
				"sessions: missing store for session %q", name))
		} else if err := session.store.Save(s.request, w, session); err != nil {
			errMulti = append(errMulti, fmt.Errorf(
				"sessions: error saving session %q -- %v", name, err))
		}
	}
	if errMulti != nil {
		return errMulti
	}
	return nil
}
1181205
func (configFile *ConfigFile) Save() error {
	if configFile.Filename == "" {
		return errors.Errorf("Can't save config with empty filename")
	}

	dir := filepath.Dir(configFile.Filename)
	if err := os.MkdirAll(dir, 0700); err != nil {
		return err
	}
	temp, err := ioutil.TempFile(dir, filepath.Base(configFile.Filename))
	if err != nil {
		return err
	}
	err = configFile.SaveToWriter(temp)
	temp.Close()
	if err != nil {
		os.Remove(temp.Name())
		return err
	}
	return os.Rename(temp.Name(), configFile.Filename)
}
85065
func Save(filename string, img image.Image, encoder Encoder) error {
	// filename = strings.TrimSuffix(filename, filepath.Ext(filename))
	f, err := os.Create(filename)
	if err != nil {
		return err
	}
	defer f.Close()
	return encoder(f, img)
}
495794
func (m *EventStore) Save(ctx context.Context, events []eh.Event, originalVersion int) error {
	if m.Err != nil {
		return m.Err
	}
	for _, event := range events {
		m.Events = append(m.Events, event)
	}
	m.Context = ctx
	return nil
}