// Save saves session to store and set cookie to response
//
// Save must be called before response header was written
766606
func (m *Manager) Save(w http.ResponseWriter, s *Session) error {
	m.setCookie(w, s)

	opt := makeStoreOption(m, s)

	// detect is flash changed and encode new flash data
	if s.flash != nil && s.flash.Changed() {
		b, _ := s.flash.encode()
		s.Set(flashKey, b)
	}

	// if session not modified, don't save to store to prevent store overflow
	if !m.config.Resave && !s.Changed() {
		return nil
	}

	// save sesion data to store
	s.Set(timestampKey, time.Now().Unix())
	return m.config.Store.Set(s.id, s.data, opt)
}
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
}
167193
func (property *Property) Save() error {
	req, err := client.NewJSONRequest(
		Config,
		"POST",
		fmt.Sprintf(
			"/papi/v1/properties?contractId=%s&groupId=%s",
			property.Contract.ContractID,
			property.Group.GroupID,
		),
		property,
	)
	if err != nil {
		return err
	}

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

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

	var location client.JSONBody
	if err = client.BodyJSON(res, &location); err != nil {
		return err
	}

	req, err = client.NewRequest(
		Config,
		"GET",
		location["propertyLink"].(string),
		nil,
	)
	if err != nil {
		return err
	}

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

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

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

	property.AccountID = properties.Properties.Items[0].AccountID
	property.Contract = properties.Properties.Items[0].Contract
	property.Group = properties.Properties.Items[0].Group
	property.ContractID = properties.Properties.Items[0].ContractID
	property.GroupID = properties.Properties.Items[0].GroupID
	property.PropertyID = properties.Properties.Items[0].PropertyID
	property.PropertyName = properties.Properties.Items[0].PropertyName
	property.LatestVersion = properties.Properties.Items[0].LatestVersion
	property.StagingVersion = properties.Properties.Items[0].StagingVersion
	property.ProductionVersion = properties.Properties.Items[0].ProductionVersion
	property.Note = properties.Properties.Items[0].Note
	property.ProductID = properties.Properties.Items[0].ProductID
	property.CloneFrom = properties.Properties.Items[0].CloneFrom

	return nil
}
229247
func (ag *AuthGroup) Save(db XODB) error {
	if ag.Exists() {
		return ag.Update(db)
	}

	return ag.Insert(db)
}
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)
}
1308623
func (target *MQTTTarget) Save(eventData event.Event) error {
	return target.store.Put(eventData)
}
1289904
func (target *WebhookTarget) Save(eventData event.Event) error {
	return target.send(eventData)
}
1087770
func (s *FilesystemStore) save(session *Session) error {
	encoded, err := securecookie.EncodeMulti(session.Name(), session.Values,
		s.Codecs...)
	if err != nil {
		return err
	}
	filename := filepath.Join(s.path, "session_"+session.ID)
	fileMutex.Lock()
	defer fileMutex.Unlock()
	return ioutil.WriteFile(filename, []byte(encoded), 0600)
}
450930
func (s *S3Storage) Save(path string, file File) error {
	return s.SaveWithContentType(path, file, mime.TypeByExtension(filepath.Ext(path)))
}
1179310
func (st *Store) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error {
	s, _ := context.Get(r, contextKey(session.Name())).(*xormSession)

	// delete if max age is < 0
	if session.Options.MaxAge < 0 {
		if s != nil {
			if _, err := st.e.Delete(&xormSession{
				ID:        session.ID,
				tableName: st.opts.TableName,
			}); err != nil {
				return err
			}
		}
		http.SetCookie(w, sessions.NewCookie(session.Name(), "", session.Options))
		return nil
	}

	data, err := securecookie.EncodeMulti(session.Name(), session.Values, st.Codecs...)
	if err != nil {
		return err
	}
	now := util.TimeStampNow()
	expire := now.AddDuration(time.Second * time.Duration(session.Options.MaxAge))

	if s == nil {
		// generate random session ID key suitable for storage in the db
		session.ID = strings.TrimRight(
			base32.StdEncoding.EncodeToString(
				securecookie.GenerateRandomKey(sessionIDLen)), "=")
		s = &xormSession{
			ID:          session.ID,
			Data:        data,
			CreatedUnix: now,
			UpdatedUnix: now,
			ExpiresUnix: expire,
			tableName:   st.opts.TableName,
		}
		if _, err := st.e.Insert(s); err != nil {
			return err
		}
		context.Set(r, contextKey(session.Name()), s)
	} else {
		s.Data = data
		s.UpdatedUnix = now
		s.ExpiresUnix = expire
		if _, err := st.e.ID(s.ID).Cols("data", "updated_unix", "expires_unix").Update(s); err != nil {
			return err
		}
	}

	// set session id cookie
	id, err := securecookie.EncodeMulti(session.Name(), session.ID, st.Codecs...)
	if err != nil {
		return err
	}
	http.SetCookie(w, sessions.NewCookie(session.Name(), id, session.Options))

	return nil
}
1167352
func (s *DumbMemoryStore) save(session *sessions.Session) error {
	encoded, err := securecookie.EncodeMulti(session.Name(), session.Values,
		s.Codecs...)
	if err != nil {
		return err
	}

	s.Data[session.ID] = encoded

	return nil
}
1233891
func (c Client) Save() error {
	settings := settingsFile{Username: c.Username, SslVerify: c.SSLVerify,
		Controller: c.ControllerURL.String(), Token: c.Token, Limit: c.ResponseLimit}

	if settings.Limit <= 0 {
		settings.Limit = DefaultResponseLimit
	}

	settingsContents, err := json.Marshal(settings)

	if err != nil {
		return err
	}

	if err = os.MkdirAll(path.Join(FindHome(), "/.deis/"), 0700); err != nil {
		return err
	}

	return ioutil.WriteFile(locateSettingsFile(), settingsContents, 0600)
}
828233
func (c *Connection) Save(model interface{}, excludeColumns ...string) error {
	sm := &Model{Value: model}
	return sm.iterate(func(m *Model) error {
		id, err := m.fieldByName("ID")
		if err != nil {
			return err
		}
		if IsZeroOfUnderlyingType(id.Interface()) {
			return c.Create(m.Value, excludeColumns...)
		}
		return c.Update(m.Value, excludeColumns...)
	})
}
1337287
func (m *GormResourceRepository) Save(ctx context.Context, resource *Resource) error {
	defer goa.MeasureSince([]string{"goa", "db", "resource", "save"}, time.Now())

	err := m.db.Save(resource).Error

	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"resource_id": resource.ResourceID,
			"err":         err,
		}, "unable to update the resource")
		return errs.WithStack(err)
	}

	log.Debug(ctx, map[string]interface{}{
		"resource_id": resource.ResourceID,
	}, "Resource saved!")

	return nil
}
345447
func Save(path string, data interface{}) error {
	err := os.MkdirAll(filepath.Dir(path), os.ModeDir+0666)
	if err != nil {
		return err
	}
	file, err := os.Create(path)
	if err != nil {
		return err
	}
	defer file.Close()
	buf, err := json.MarshalIndent(data, "", "    ")
	if err != nil {
		return err
	}
	_, err = io.Copy(file, bytes.NewReader(buf))
	return err
}
144461
func (ds *DjangoSession) Save(db XODB) error {
	if ds.Exists() {
		return ds.Update(db)
	}

	return ds.Insert(db)
}
1193103
func (s *sessionV8) Save() *probe.Error {
	s.mutex.Lock()
	defer s.mutex.Unlock()

	if s.DataFP.dirty {
		if err := s.DataFP.Sync(); err != nil {
			return probe.NewError(err)
		}
		s.DataFP.dirty = false
	}

	qs, e := quick.NewConfig(s.Header, nil)
	if e != nil {
		return probe.NewError(e).Trace(s.SessionID)
	}

	sessionFile, err := getSessionFile(s.SessionID)
	if err != nil {
		return err.Trace(s.SessionID)
	}
	e = qs.Save(sessionFile)
	if e != nil {
		return probe.NewError(e).Trace(sessionFile)
	}
	return nil
}