// SaveEmptyRoot creates an entry on disk for an empty root.
776386
func (ndb *nodeDB) SaveEmptyRoot(version int64) error {
	return ndb.saveRoot([]byte{}, version)
}
1192161
func (o *ObjectToPack) SaveOriginalMetadata() {
	if o.Original != nil {
		o.originalSize = o.Original.Size()
		o.originalType = o.Original.Type()
		o.originalHash = o.Original.Hash()
		o.resolvedOriginal = true
	}
}
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)
}
1362460
func (p *LogPrefix) Save(withMeta bool) (ds.PropertyMap, error) {
	if err := p.validateImpl(true); err != nil {
		return nil, err
	}
	p.Schema = CurrentSchemaVersion

	return ds.GetPLS(p).Save(withMeta)
}
563539
func (md *RootMetadata) SetPrevRoot(mdID kbfsmd.ID) {
	md.bareMd.SetPrevRoot(mdID)
}
991992
func (e *EnsureAttempt) Root(c context.Context) *ds.Key {
	return model.AttemptKeyFromID(c, e.ID)
}
1326609
func (r *GormQueryRepository) Save(ctx context.Context, q Query) (*Query, error) {
	defer goa.MeasureSince([]string{"goa", "db", "query", "save"}, time.Now())
	if strings.TrimSpace(q.Title) == "" {
		return nil, errors.NewBadParameterError("query title cannot be empty string", q.Title).Expected("non empty string")
	}
	var v map[string]interface{}
	if err := json.Unmarshal([]byte(q.Fields), &v); err != nil {
		return nil, errors.NewBadParameterError("query field is invalid JSON syntax", q.Fields).Expected("valid JSON")
	}
	qry := Query{}
	tx := r.db.Where("id = ?", q.ID).First(&qry)
	oldVersion := q.Version
	q.Version = qry.Version + 1
	if tx.RecordNotFound() {
		log.Error(ctx, map[string]interface{}{
			"query_id": q.ID,
		}, "query cannot be found")
		return nil, errors.NewNotFoundError("query", q.ID.String())
	}
	if err := tx.Error; err != nil {
		log.Error(ctx, map[string]interface{}{
			"query_id": q.ID,
			"err":      err,
		}, "unknown error happened when searching the query")
		return nil, errors.NewInternalError(ctx, err)
	}
	tx = tx.Where("Version = ?", oldVersion).Save(&q)
	if err := tx.Error; err != nil {
		// combination of name and space ID should be unique
		if gormsupport.IsUniqueViolation(err, "queries_title_space_id_creator_unique") {
			log.Error(ctx, map[string]interface{}{
				"err":      err,
				"title":    q.Title,
				"space_id": q.SpaceID,
			}, "unable to create query because a query with same title already exists in the space")
			return nil, errors.NewDataConflictError(fmt.Sprintf("query already exists with title = %s , space_id = %s", q.Title, q.SpaceID.String()))
		}
		log.Error(ctx, map[string]interface{}{
			"query_id": q.ID,
			"err":      err,
		}, "unable to save the query")
		return nil, errors.NewInternalError(ctx, err)
	}
	if tx.RowsAffected == 0 {
		return nil, errors.NewVersionConflictError("version conflict")
	}
	log.Debug(ctx, map[string]interface{}{
		"query_id": q.ID,
	}, "query updated successfully")

	return &q, nil
}
1093604
func getRootlessStorageOpts(rootlessUid int) (StoreOptions, error) {
	var opts StoreOptions

	dataDir, rootlessRuntime, err := getRootlessDirInfo(rootlessUid)
	if err != nil {
		return opts, err
	}
	opts.RunRoot = rootlessRuntime
	opts.GraphRoot = filepath.Join(dataDir, "containers", "storage")
	if path, err := exec.LookPath("fuse-overlayfs"); err == nil {
		opts.GraphDriverName = "overlay"
		opts.GraphDriverOptions = []string{fmt.Sprintf("overlay.mount_program=%s", path)}
	} else {
		opts.GraphDriverName = "vfs"
	}
	return opts, 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)
	}
}
1005829
func (ndb *nodeDB) SaveBranch(node *Node) []byte {
	if node.persisted {
		return node.hash
	}

	if node.leftNode != nil {
		node.leftHash = ndb.SaveBranch(node.leftNode)
	}
	if node.rightNode != nil {
		node.rightHash = ndb.SaveBranch(node.rightNode)
	}

	node._hash()
	ndb.SaveNode(node)

	node.leftNode = nil
	node.rightNode = nil

	return node.hash
}
122896
func (b MongodbAuthBackend) SaveUser(user UserData) error {
	c := b.connect()
	defer c.Database.Session.Close()

	_, err := c.Upsert(bson.M{"Username": user.Username}, bson.M{"$set": user})
	return err
}
411519
func (s *Store) removeEmptyParentDirectories(path string) error {
	parent := filepath.Dir(path)

	if relpath, err := filepath.Rel(s.path, parent); err != nil {
		return err
	} else if strings.HasPrefix(relpath, ".") {
		return nil
	}

	err := os.Remove(parent)
	switch {
	case err == nil:
		return s.removeEmptyParentDirectories(parent)
	case err.(*os.PathError).Err == syscall.ENOTEMPTY:
		// ignore when directory is non-empty
		return nil
	default:
		return err
	}
}
424790
func (ndb *nodeDB) SaveNode(node *Node) {
	ndb.mtx.Lock()
	defer ndb.mtx.Unlock()

	if node.hash == nil {
		panic("Expected to find node.hash, but none found.")
	}
	if node.persisted {
		panic("Shouldn't be calling save on an already persisted node.")
	}

	// Save node bytes to db.
	buf := new(bytes.Buffer)
	if err := node.writeBytes(buf); err != nil {
		panic(err)
	}
	ndb.batch.Set(ndb.nodeKey(node.hash), buf.Bytes())
	debug("BATCH SAVE %X %p\n", node.hash, node)

	node.persisted = true
	ndb.cacheNode(node)
}
889899
func (c Config) Save(file string) error {
	var s = fileOutput(c.root)
	return ioutil.WriteFile(file, []byte(s), 0666)
}
741123
func (h *Hive) savePeers() error {
	var peers []*BzzAddr
	h.Kademlia.EachAddr(nil, 256, func(pa *BzzAddr, i int) bool {
		if pa == nil {
			log.Warn(fmt.Sprintf("empty addr: %v", i))
			return true
		}
		log.Trace("saving peer", "peer", pa)
		peers = append(peers, pa)
		return true
	})
	if err := h.Store.Put("peers", peers); err != nil {
		return fmt.Errorf("could not save peers: %v", err)
	}
	return nil
}
68574
func fastRepoRoot(rootImportPath string) (*repoRoot, error) {
	pkg, err := build.Import(rootImportPath, "", build.FindOnly)
	if err != nil {
		return nil, err
	}

	vcs, err := lookVCS(pkg.Dir)
	if err != nil {
		return nil, err
	}

	return &repoRoot{
		vcs:  vcs,
		repo: "",
		path: pkg.Dir,
		root: rootImportPath,
	}, nil
}
1293032
func (c *Conf) Save(src interface{}) (err error) {
	nb, err := json.Marshal(src)
	if err != nil {
		return
	}

	err = ioutil.WriteFile(c.Path(), nb, 0666)
	if err != nil {
		return
	}

	return
}