// save writes encoded session.Values using the memcache client
19004
func (s *MemcacheStore) save(session *sessions.Session) error {

	key := s.KeyPrefix + session.ID

	switch s.StoreMethod {

	case StoreMethodSecureCookie:

		encoded, err := securecookie.EncodeMulti(session.Name(), session.Values,
			s.Codecs...)
		if err != nil {
			if s.Logging > 0 {
				log.Printf("gorilla-sessions-memcache: set (method: securecookie, encoding error: %v)", err)
			}
			return err
		}

		_, err = s.Client.Set(key, encoded, 0, uint32(session.Options.MaxAge), 0)
		if s.Logging > 0 {
			log.Printf("gorilla-sessions-memcache: set (method: securecookie, session name: %v, memcache key: %v, memcache value: %v, error: %v)", session.Name(), key, encoded, err)
		}
		if err != nil {
			return err
		}

		return nil

	case StoreMethodGob:

		buf := &bytes.Buffer{}
		enc := gob.NewEncoder(buf)
		err := enc.Encode(session.Values)
		if err != nil {
			if s.Logging > 0 {
				log.Printf("gorilla-sessions-memcache: set (method: gob, encoding error: %v)", err)
			}
			return err
		}
		bufbytes := buf.Bytes()

		_, err = s.Client.Set(key, string(bufbytes), 0, uint32(session.Options.MaxAge), 0)
		if s.Logging > 0 {
			log.Printf("gorilla-sessions-memcache: set (method: gob, session name: %v, memcache key: %v, memcache value len: %v, error: %v)", session.Name(), key, len(bufbytes), err)
		}
		if err != nil {
			return err
		}

		return nil

	case StoreMethodJson:

		vals := make(map[string]interface{}, len(session.Values))
		for k, v := range session.Values {
			ks, ok := k.(string)
			if !ok {
				err := fmt.Errorf("Non-string key value, cannot jsonize: %v", k)
				log.Printf("gorilla-sessions-memcache: set (method: json, encoding error: %v)", err)
				return err
			}
			vals[ks] = v
		}

		bufbytes, err := json.Marshal(vals)
		if err != nil {
			if s.Logging > 0 {
				log.Printf("gorilla-sessions-memcache: set (method: json, encoding error: %v)", err)
			}
			return err
		}

		_, err = s.Client.Set(key, string(bufbytes), 0, uint32(session.Options.MaxAge), 0)
		if s.Logging > 0 {
			log.Printf("gorilla-sessions-memcache: set (method: json, session name: %v, memcache key: %v, memcache value: %v, error: %v)", session.Name(), key, string(bufbytes), err)
		}
		if err != nil {
			return err
		}

		return nil

	default:
		panic("Unknown StoreMethod: " + string(s.StoreMethod))
	}

	panic("Unreachable")
	return nil
}
991070
func (m *Mem) Save(key models.Key, model models.Model) error {
	m.mut.Lock()
	defer m.mut.Unlock()
	m.m[key.String()] = model
	return nil
}
232708
func (o *OAuthSession) Save(v Voter, category string) error {
	// Build form for POST request.
	form := url.Values{
		"id":       {v.voteID()},
		"category": {category},
	}
	var s interface{}

	err := o.postBody("https://oauth.reddit.com/api/save", form, s)
	if err != nil {
		return err
	}
	return nil
}
595333
func (m *MemStore) Save(r *http.Request, w http.ResponseWriter, s *sessions.Session) error {
	var cookieValue string
	if s.Options.MaxAge < 0 {
		cookieValue = ""
		m.cache.delete(s.Name())
		for k := range s.Values {
			delete(s.Values, k)
		}
	} else {
		if s.ID == "" {
			s.ID = strings.TrimRight(base32.StdEncoding.EncodeToString(securecookie.GenerateRandomKey(32)), "=")
		}
		encrypted, err := securecookie.EncodeMulti(s.Name(), s.ID, m.Codecs...)
		if err != nil {
			return err
		}
		cookieValue = encrypted
		m.cache.setValue(s.ID, m.copy(s.Values))
	}
	http.SetCookie(w, sessions.NewCookie(s.Name(), cookieValue, s.Options))
	return nil
}
1315557
func (client *Client) Save() error {
    _, err := client.sendCommand("SAVE")
    if err != nil {
        return err
    }
    return nil
}
1331411
func (pwm *Manager) Save(username, password string) error {
	//TODO: username and password validation
	passwordHash, err := keyderivation.Hash(password)
	if err != nil {
		log.Error("ERROR hashing password")
		log.Debug("ERROR hashing password: ", err)
		return errors.New("internal_error")
	}
	if len(password) < passwordMinLength {
		return errors.New("invalid_password")
	}
	storedPassword := userPass{Username: username, Password: passwordHash}

	_, err = pwm.collection.Upsert(bson.M{"username": username}, storedPassword)

	return err
}
1085193
func (s *Session) Save(w http.ResponseWriter) error {
	return s.store.Save(w, s)
}
193525
func (pwm *Manager) Save(username, secret string) error {
	//TODO: username and secret validation

	storedSecret := userSecret{Username: username, Secret: secret}

	_, err := pwm.collection.Upsert(bson.M{"username": username}, storedSecret)

	return err
}
237095
func (h *handler) Save(w http.ResponseWriter, s *Session) error {
	if !s.isDirty {
		return nil
	}

	defer http.SetCookie(w, s.Cookie)

	// If session was destroyed by user, make sure the destroy operation
	// from external Store is also invoked.
	if s.MaxAge == -1 && h.store != nil {
		return h.store.Destroy(s.Value)
	}

	data, err := s.Encode()
	if err != nil {
		return err
	}

	if h.store != nil {
		return h.store.Save(s.Value, data)
	}

	s.Value = string(data[:])
	return nil
}
80184
func (p *Pubring) Save() error {
	buf, err := proto.Marshal(p.data)
	if err != nil {
		return err
	}
	return ioutil.WriteFile(p.File, buf, 0600)
}
1346787
func (m *SnapshotMetadata) save() error {
	// This is not safe for concurrent access.
	// Exported methods will deal with locking.
	jsonData, err := json.Marshal(m.snapshotMetadata)
	if err != nil {
		glog.Errorf("Error encoding metadata to json: %s", err)
		return ErrInvalidMetadata
	}
	return ioutil.WriteFile(m.path, jsonData, 0644)
}
1233468
func (s *CookieStore) Save(r *http.Request, w http.ResponseWriter,
	session *Session) error {
	encoded, err := securecookie.EncodeMulti(session.Name(), session.Values,
		s.Codecs...)
	if err != nil {
		return err
	}
	http.SetCookie(w, NewCookie(session.Name(), encoded, session.Options))
	return nil
}
1305330
func (c *Client) Save(metadata []params.CloudImageMetadata) error {
	in := params.MetadataSaveParams{
		Metadata: []params.CloudImageMetadataList{{metadata}},
	}
	out := params.ErrorResults{}
	err := c.facade.FacadeCall("Save", in, &out)
	if err != nil {
		return errors.Trace(err)
	}
	if len(out.Results) != 1 {
		return errors.Errorf("exected 1 result, got %d", len(out.Results))
	}
	if out.Results[0].Error != nil {
		return errors.Trace(out.Results[0].Error)
	}
	return nil
}
1233254
func (ss *Snapshot) save() error {
	// Open the file for writing.
	file, err := os.OpenFile(ss.Path, os.O_CREATE|os.O_WRONLY, 0600)
	if err != nil {
		return err
	}
	defer file.Close()

	// Serialize to JSON.
	b, err := json.Marshal(ss)
	if err != nil {
		return err
	}

	// Generate checksum and write it to disk.
	checksum := crc32.ChecksumIEEE(b)
	if _, err = fmt.Fprintf(file, "%08x\n", checksum); err != nil {
		return err
	}

	// Write the snapshot to disk.
	if _, err = file.Write(b); err != nil {
		return err
	}

	// Ensure that the snapshot has been flushed to disk before continuing.
	if err := file.Sync(); err != nil {
		return err
	}

	return nil
}
965438
func (c *TagCache) Save(ctx context.Context) error {
	c.lock.Lock()
	defer c.lock.Unlock()

	// Nothing to store? Just clean the state, so that ResolveTag can fetch the
	// up-to-date cache from disk later if needed.
	if len(c.addedTags) == 0 && len(c.addedFiles) == 0 {
		c.cache = nil
		return nil
	}

	// Sort all new entries, for consistency.
	sortedTags := make([]string, 0, len(c.addedTags))
	for k := range c.addedTags {
		sortedTags = append(sortedTags, string(k))
	}
	sort.Strings(sortedTags)
	sortedFiles := make([]string, 0, len(c.addedFiles))
	for k := range c.addedFiles {
		sortedFiles = append(sortedFiles, string(k))
	}
	sort.Strings(sortedFiles)

	// Load the most recent data to avoid overwriting it. Load ALL entries, even
	// if they belong to different service: we have one global cache file and
	// should preserve all entries there.
	recent, err := c.loadFromDisk(ctx, true)
	if err != nil {
		return err
	}

	// Copy existing entries, except the ones we are moving to the tail. Carefully
	// copy entries belonging to other services too, we must not overwrite them.
	mergedTags := make([]*messages.TagCache_Entry, 0, len(recent.Entries)+len(c.addedTags))
	for _, e := range recent.Entries {
		key := makeTagKey(e.Package, e.Tag)
		if e.Service != c.service || c.addedTags[key] == nil {
			mergedTags = append(mergedTags, e)
		}
	}

	// Add new entries to the tail.
	for _, k := range sortedTags {
		mergedTags = append(mergedTags, c.addedTags[tagKey(k)])
	}

	// Trim the end result, discard the head: it's where old items are.
	if len(mergedTags) > tagCacheMaxSize {
		mergedTags = mergedTags[len(mergedTags)-tagCacheMaxSize:]
	}

	// Do the same for file entries.
	mergedFiles := make([]*messages.TagCache_FileEntry, 0, len(recent.FileEntries)+len(c.addedFiles))
	for _, e := range recent.FileEntries {
		key := makeFileKey(e.Package, e.InstanceId, e.FileName)
		if e.Service != c.service || c.addedFiles[key] == nil {
			mergedFiles = append(mergedFiles, e)
		}
	}
	for _, k := range sortedFiles {
		mergedFiles = append(mergedFiles, c.addedFiles[fileKey(k)])
	}
	if len(mergedFiles) > tagCacheMaxExeSize {
		mergedFiles = mergedFiles[len(mergedFiles)-tagCacheMaxExeSize:]
	}

	// Serialize and write to disk. We still can accidentally replace someone
	// else's changes, but the probability should be relatively low. It can happen
	// only if two processes call 'Save' at the exact same time.
	updated := &messages.TagCache{Entries: mergedTags, FileEntries: mergedFiles}
	if err := c.dumpToDisk(ctx, updated); err != nil {
		return err
	}

	// The state is persisted now.
	c.cache = updated
	c.addedTags = nil
	c.addedFiles = nil

	return nil
}
1128522
func (n *Netrc) Save() error {
	body := []byte(n.Render())
	if filepath.Ext(n.Path) == ".gpg" {
		cmd := exec.Command("gpg", "-a", "--batch", "--default-recipient-self", "-e")
		stdin, err := cmd.StdinPipe()
		if err != nil {
			return err
		}
		stdin.Write(body)
		stdin.Close()
		cmd.Stderr = os.Stderr
		body, err = cmd.Output()
		if err != nil {
			return err
		}
	}
	return ioutil.WriteFile(n.Path, body, 0600)
}
1275199
func (clientSettings *ClientSettings) Save() error {
	req, err := client.NewJSONRequest(
		Config,
		"PUT",
		"/papi/v1/client-settings",
		clientSettings,
	)
	if err != nil {
		return err
	}

	res, err := client.Do(Config, req)
	if err != nil {
		return err
	}

	if client.IsError(res) {
		return client.NewAPIError(res)
	}

	newClientSettings := NewClientSettings()
	if err := client.BodyJSON(res, newClientSettings); err != nil {
		return err
	}

	clientSettings.RuleFormat = newClientSettings.RuleFormat

	return nil
}