// SaveBottle persists bottle to bottlesbase.
772767
func (db *DB) SaveBottle(model BottleModel) {
	db.Lock()
	defer db.Unlock()

	bottles, found := db.bottles[model.AccountID]
	if found {
		for i := 0; i < len(bottles); i++ {
			if bottles[i].ID == model.ID {
				bottles[i] = &model
				break
			}
		}
	} else {
		db.bottles[model.AccountID] = append(db.bottles[model.AccountID], &model)
	}
}
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
}
314327
func (dt *DbfTable) SaveFile(filename string) error {
	// don't forget to add dbase end of file marker which is 1Ah
	dt.dataStore = appendSlice(dt.dataStore, []byte{0x1A})
	f, err := os.Create(filename)
	if err != nil {
		return err
	}
	defer f.Close()

	_, err = f.Write(dt.dataStore)
	if err != nil {
		return err
	}
	return nil
}
1034664
func (e *Kex2Provisionee) saveKeys(m libkb.MetaContext) error {
	_, err := libkb.WriteLksSKBToKeyring(m, e.eddsa, e.lks)
	if err != nil {
		return err
	}
	_, err = libkb.WriteLksSKBToKeyring(m, e.dh, e.lks)
	if err != nil {
		return err
	}
	return nil
}
913949
func (b *BottleController) Rate(ctx *app.RateBottleContext) error {
	bottle, ok := b.db.GetBottle(ctx.AccountID, ctx.BottleID)
	if !ok {
		return ctx.NotFound()
	}
	bottle.Rating = &ctx.Payload.Rating
	bottle.UpdatedAt = time.Now()
	b.db.SaveBottle(bottle)
	return ctx.NoContent()
}
941299
func (b *BottleController) Create(ctx *app.CreateBottleContext) error {
	bottle, err := b.db.NewBottle(ctx.AccountID)
	if err != nil {
		return ctx.NotFound()
	}
	payload := ctx.Payload
	bottle.Name = payload.Name
	bottle.Vintage = payload.Vintage
	bottle.Vineyard = payload.Vineyard
	bottle.CreatedAt = time.Now()
	bottle.UpdatedAt = bottle.CreatedAt
	if payload.Varietal != "" {
		bottle.Varietal = payload.Varietal
	}
	if payload.Color != "" {
		bottle.Color = payload.Color
	}
	if payload.Sweetness != nil {
		bottle.Sweetness = payload.Sweetness
	}
	if payload.Country != nil {
		bottle.Country = payload.Country
	}
	if payload.Region != nil {
		bottle.Region = payload.Region
	}
	if payload.Review != nil {
		bottle.Review = payload.Review
	}
	b.db.SaveBottle(bottle)
	ctx.ResponseData.Header().Set("Location", app.BottleHref(ctx.AccountID, bottle.ID))
	return ctx.Created()
}
1230942
func (s *DB) Save(value interface{}) *DB {
	scope := s.NewScope(value)
	if !scope.PrimaryKeyZero() {
		newDB := scope.callCallbacks(s.parent.callbacks.updates).db
		if newDB.Error == nil && newDB.RowsAffected == 0 {
			return s.New().FirstOrCreate(value)
		}
		return newDB
	}
	return scope.callCallbacks(s.parent.callbacks.creates).db
}
751968
func (s *server) saveSnapshot() error {
	if s.pendingSnapshot == nil {
		return errors.New("pendingSnapshot.is.nil")
	}

	// Write snapshot to disk.
	if err := s.pendingSnapshot.save(); err != nil {
		return err
	}

	// Swap the current and last snapshots.
	tmp := s.snapshot
	s.snapshot = s.pendingSnapshot

	// Delete the previous snapshot if there is any change
	if tmp != nil && !(tmp.LastIndex == s.snapshot.LastIndex && tmp.LastTerm == s.snapshot.LastTerm) {
		tmp.remove()
	}
	s.pendingSnapshot = nil

	return nil
}
110023
func (c *Client) DecodeBottle(resp *http.Response) (*Bottle, error) {
	var decoded Bottle
	err := c.Decoder.Decode(&decoded, resp.Body, resp.Header.Get("Content-Type"))
	return &decoded, err
}
1082911
func (rt *RandomTree) Save(filePath string) error {
	writer, err := base.CreateSerializedClassifierStub(filePath, rt.GetMetadata())
	if err != nil {
		return err
	}
	defer func() {
		writer.Close()
	}()
	return rt.SaveWithPrefix(writer, "")
}
237795
func (b *Bag) Save() (errs []error) {

	errors := b.savePayloadManifests()
	if len(errors) > 0 {
		errs = append(errs, errors...)
	}

	errors = b.calculateChecksumsForManagedTagFiles()
	if len(errors) > 0 {
		errs = append(errs, errors...)
	}

	errors = b.calculateChecksumsForCustomTagFiles()
	if len(errors) > 0 {
		errs = append(errs, errors...)
	}

	errors = b.saveTagManifests()
	if len(errors) > 0 {
		errs = append(errs, errors...)
	}

	return errs
}
572320
func (d *Database) Save(db DB, table string, src interface{}) error {
	pkName, pkValue, err := d.PrimaryKey(src)
	if err != nil {
		return err
	}
	if pkName != "" && pkValue != 0 {
		return d.Update(db, table, src)
	}

	return d.Insert(db, table, src)
}
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)
}
1013383
func (b *BottleController) Watch(ctx *app.WatchBottleContext) error {
	Watcher(ctx.AccountID, ctx.BottleID).ServeHTTP(ctx.ResponseWriter, ctx.Request)
	return nil
}
819866
func (db *database) SaveEntity(e Entity) error {
	b, err := json.Marshal(e)

	if err != nil {
		return err
	}

	return db.storage.Set(toEntityKey(e.Name), b)
}
587576
func (db *memDB) Save(c *Container) error {
	return db.withTxn(func(txn *memdb.Txn) error {
		return txn.Insert(memdbContainersTable, c)
	})
}
1185905
func (c *Client) RateBottle(ctx context.Context, path string, payload *RateBottlePayload, contentType string) (*http.Response, error) {
	req, err := c.NewRateBottleRequest(ctx, path, payload, contentType)
	if err != nil {
		return nil, err
	}
	return c.Client.Do(ctx, req)
}