// Save save data in json format into the given file
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
}
1118814
func (h *history) Save() (err error) {
	if _, err = h.file.Seek(0, 0); err != nil {
		return
	}

	out := bufio.NewWriter(h.file)
	element := h.li.Front() // Get the first element.

	for i := 0; i < h.li.Len(); i++ {
		line := element.Value.(string)

		if strings.HasPrefix(line, " ") {
			goto _next
		}
		if line = strings.TrimSpace(line); line == "" {
			goto _next
		}
		if _, err = out.WriteString(line + "\n"); err != nil {
			log.Println("history.Save:", err)
			break
		}

	_next:
		if element = element.Next(); element == nil {
			continue
		}
	}

	if err = out.Flush(); err != nil {
		log.Println("history.Save:", err)
	}

	h.close()
	return
}
1015125
func (rwt *RWTree) Save() ([]byte, int64, error) {
	// save state at a new version may still be orphaned before we save the version against the hash
	hash, version, err := rwt.tree.SaveVersion()
	if err != nil {
		return nil, 0, fmt.Errorf("could not save RWTree: %v", err)
	}
	// Take an immutable reference to the tree we just saved for querying
	rwt.ImmutableTree, err = rwt.tree.GetImmutable(version)
	if err != nil {
		return nil, 0, fmt.Errorf("RWTree.Save() could not obtain ImmutableTree read tree: %v", err)
	}
	rwt.updated = false
	return hash, version, nil
}
818479
func (r *Rules) Save(filename string) (err error) {
	cfilename := C.CString(filename)
	defer C.free(unsafe.Pointer(cfilename))
	err = newError(C.yr_rules_save(r.cptr, cfilename))
	keepAlive(r)
	return
}
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)
}
68973
func (d *DecisionTreeNode) Save(filePath string) error {
	metadata := base.ClassifierMetadataV1{
		FormatVersion:     1,
		ClassifierName:    "test",
		ClassifierVersion: "1",
	}
	serializer, err := base.CreateSerializedClassifierStub(filePath, metadata)
	if err != nil {
		return err
	}
	err = d.SaveWithPrefix(serializer, "")
	if err != nil {
		return err
	}
	return serializer.Close()
}
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)
}
884886
func (t *ContainerVolumeTracker) Save(containerID, tempDir string, client *docker.Client) error {
	if t == nil {
		return nil
	}
	set := imagebuilder.VolumeSet{}
	for dest := range t.paths {
		set.Add(dest)
	}
	// remove archive paths that are covered by other paths
	for dest := range t.paths {
		if !set.Has(dest) {
			t.ReleasePath(dest)
			delete(t.paths, dest)
		}
	}
	for dest, archivePath := range t.paths {
		if len(archivePath) > 0 {
			continue
		}
		archivePath, err := snapshotPath(dest, containerID, tempDir, client)
		if err != nil {
			return err
		}
		t.paths[dest] = archivePath
	}
	return nil
}
987169
func (o *FileSystemSaver) Save(store uuid.Store) {

	if store.Timestamp >= o.Timestamp {
		err := o.openAndDo(o.encode, &store)
		if err == nil {
			if o.Report {
				o.Println("file system saver saved", store)
			}
		}
		o.Timestamp = store.Add(o.Duration)
	}
}
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)
}
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
}
824605
func (f *File) Save(name string) error {
	return ioutil.WriteFile(name, []byte(f.String()), 0666)
}
80184
func (p *Pubring) Save() error {
	buf, err := proto.Marshal(p.data)
	if err != nil {
		return err
	}
	return ioutil.WriteFile(p.File, buf, 0600)
}
1867
func (api *API) Save(metadata params.MetadataSaveParams) (params.ErrorResults, error) {
	all, err := imagecommon.Save(api.metadata, metadata)
	if err != nil {
		return params.ErrorResults{}, errors.Trace(err)
	}
	return params.ErrorResults{Results: all}, nil
}
742490
func (c *JSONConfigContainer) SaveConfigFile(filename string) (err error) {
	// Write configuration file by filename.
	f, err := os.Create(filename)
	if err != nil {
		return err
	}
	defer f.Close()
	b, err := json.MarshalIndent(c.data, "", "  ")
	if err != nil {
		return err
	}
	_, err = f.Write(b)
	return err
}
569280
func (i *InstallReceipt) Save(w io.Writer) error {
	data, err := json.MarshalIndent(i, "", "  ")
	if err != nil {
		return err
	}
	_, err = w.Write(data)
	w.Write([]byte("\n"))
	return err
}
1122870
func (j *Job) save() error {
	t := newTransaction()
	t.saveJob(j)
	if err := t.exec(); err != nil {
		return err
	}
	return nil
}