// Put implements the MDServer interface for MDServerDisk.
320193
func (md *MDServerDisk) Put(ctx context.Context, rmds *RootMetadataSigned,
	extra kbfsmd.ExtraMetadata, _ *keybase1.LockContext, _ keybase1.MDPriority) error {
	if err := checkContext(ctx); err != nil {
		return err
	}

	session, err := md.config.currentSessionGetter().GetCurrentSession(ctx)
	if err != nil {
		return kbfsmd.ServerError{Err: err}
	}

	tlfStorage, err := md.getStorage(rmds.MD.TlfID())
	if err != nil {
		return err
	}

	recordBranchID, err := tlfStorage.put(
		ctx, session.UID, session.VerifyingKey, rmds, extra)
	if err != nil {
		return err
	}

	// Record branch ID
	if recordBranchID {
		err = md.putBranchID(ctx, rmds.MD.TlfID(), rmds.MD.BID())
		if err != nil {
			return kbfsmd.ServerError{Err: err}
		}
	}

	mStatus := rmds.MD.MergedStatus()
	if mStatus == kbfsmd.Merged &&
		// Don't send notifies if it's just a rekey (the real mdserver
		// sends a "folder needs rekey" notification in this case).
		!(rmds.MD.IsRekeySet() && rmds.MD.IsWriterMetadataCopiedSet()) {
		md.updateManager.setHead(rmds.MD.TlfID(), md)
	}

	return nil
}
696365
func (d *Driver) Put(id string) error {
	title := fmt.Sprintf("lcowdriver: put: %s", id)

	// Get the service VM that we need to remove from
	svm, err := d.serviceVms.get(d.getVMID(id))
	if err == errVMUnknown {
		return nil
	} else if err == errVMisTerminating {
		return svm.getStopError()
	}

	// Generate the mounts that Get() might have mounted
	disks, err := d.getAllMounts(id)
	if err != nil {
		logrus.Debugf("%s failed to get all layer details for %s: %s", title, d.dir(id), err)
		return fmt.Errorf("%s failed to get layer details for %s: %s", title, d.dir(id), err)
	}

	// Now, we want to perform the unmounts, hot-remove and stop the service vm.
	// We want to go though all the steps even if we have an error to clean up properly
	err = svm.deleteUnionMount(unionMountName(disks), disks...)
	if err != nil {
		logrus.Debugf("%s failed to delete union mount %s: %s", title, id, err)
	}

	err1 := svm.hotRemoveVHDs(disks...)
	if err1 != nil {
		logrus.Debugf("%s failed to hot remove vhds %s: %s", title, id, err)
		if err == nil {
			err = err1
		}
	}

	err1 = d.terminateServiceVM(id, fmt.Sprintf("Put %s", id), false)
	if err1 != nil {
		logrus.Debugf("%s failed to terminate service vm %s: %s", title, id, err1)
		if err == nil {
			err = err1
		}
	}
	logrus.Debugf("Put succeeded on id %s", id)
	return err
}
1237693
func (md *MDOpsStandard) Put(ctx context.Context, rmd *RootMetadata,
	verifyingKey kbfscrypto.VerifyingKey, lockContext *keybase1.LockContext,
	priority keybase1.MDPriority) (ImmutableRootMetadata, error) {
	if rmd.MergedStatus() == kbfsmd.Unmerged {
		return ImmutableRootMetadata{}, UnexpectedUnmergedPutError{}
	}
	return md.put(ctx, rmd, verifyingKey, lockContext, priority)
}
138865
func (s *AESEncryptedStorage) Put(key, value string) {
	if len(key) == 0 {
		return
	}
	data, err := s.readEncryptedStorage()
	if err != nil {
		log.Warn("Failed to read encrypted storage", "err", err, "file", s.filename)
		return
	}
	ciphertext, iv, err := encrypt(s.key, []byte(value), []byte(key))
	if err != nil {
		log.Warn("Failed to encrypt entry", "err", err)
		return
	}
	encrypted := storedCredential{Iv: iv, CipherText: ciphertext}
	data[key] = encrypted
	if err = s.writeEncryptedStorage(data); err != nil {
		log.Warn("Failed to write entry", "err", err)
	}
}
630880
func (c FakeClient) Put(path string, value interface{}) error {
	return c.repo.resourcesData.Put(path, value)
}
1004094
func (dds *Delayed) Put(key ds.Key, value []byte) (err error) {
	dds.delay.Wait()
	return dds.ds.Put(key, value)
}
261790
func (b *BlockServerDisk) Put(
	ctx context.Context, tlfID tlf.ID, id kbfsblock.ID,
	context kbfsblock.Context, buf []byte,
	serverHalf kbfscrypto.BlockCryptKeyServerHalf,
	_ DiskBlockCacheType) (err error) {
	if err := checkContext(ctx); err != nil {
		return err
	}

	defer func() {
		err = translateToBlockServerError(err)
	}()
	b.log.CDebugf(ctx, "BlockServerDisk.Put id=%s tlfID=%s context=%s size=%d",
		id, tlfID, context, len(buf))

	if context.GetRefNonce() != kbfsblock.ZeroRefNonce {
		return errors.New("can't Put() a block with a non-zero refnonce")
	}

	tlfStorage, err := b.getStorage(tlfID)
	if err != nil {
		return err
	}

	tlfStorage.lock.Lock()
	defer tlfStorage.lock.Unlock()
	if tlfStorage.store == nil {
		return errBlockServerDiskShutdown
	}

	_, err = tlfStorage.store.put(ctx, true, id, context, buf, serverHalf)
	if err != nil {
		return err
	}
	err = tlfStorage.store.addReference(ctx, id, context, "tag")
	if err != nil {
		return err
	}
	return nil
}
1016142
func (d datastore) Put(path string, data interface{}) error {
	d[path] = data
	return nil
}
643363
func (c *RemoteClient) Put(data []byte) error {
	if c.expireSecs != 0 {
		log.Printf("[DEBUG] ExpireSecs = %d", c.expireSecs)
		return c.put(c.objectName, data, c.expireSecs, "")
	}

	return c.put(c.objectName, data, -1, "")

}
1337717
func (d *Driver) Put(id string) error {
	mp := path.Join(d.home, "mnt", id)
	err := d.DeviceSet.UnmountDevice(id, mp)
	if err != nil {
		logrus.Errorf("devmapper: Error unmounting device %s: %s", id, err)
	}
	return err
}
672015
func (dbcr *DiskBlockCacheRemote) Put(ctx context.Context, tlfID tlf.ID,
	blockID kbfsblock.ID, buf []byte,
	serverHalf kbfscrypto.BlockCryptKeyServerHalf,
	_ DiskBlockCacheType) (err error) {
	dbcr.log.LazyTrace(ctx, "DiskBlockCacheRemote: Put %s", blockID)
	defer func() {
		dbcr.log.LazyTrace(ctx, "DiskBlockCacheRemote: Put %s done (err=%+v)", blockID, err)
	}()

	return dbcr.client.PutBlock(ctx, kbgitkbfs.PutBlockArg{
		TlfID:      tlfID.Bytes(),
		BlockID:    blockID.Bytes(),
		Buf:        buf,
		ServerHalf: serverHalf.Bytes(),
	})
}
753754
func (s *OrganizationConfigStore) Put(ctx context.Context, c *chronograf.OrganizationConfig) error {
	err := validOrganization(ctx)
	if err != nil {
		return err
	}

	return s.store.Put(ctx, c)
}
1370759
func (c *Client) Put(key string, data []byte, opts ...datasync.PutOption) error {
	newEntry := &decoder.FileDataEntry{Key: key, Value: data}
	statusDataEntries := c.db.GetDataForFile(c.statusPath)
	// Add/update data
	var updated bool
	for _, statusDataEntry := range statusDataEntries {
		if statusDataEntry.Key == key {
			statusDataEntry.Value = data
			updated = true
			break
		}
	}
	if !updated {
		statusDataEntries = append(statusDataEntries, newEntry)
	}
	c.db.Add(c.statusPath, newEntry)
	// Encode and write
	stFileEntries, err := c.statusDecoder.Encode(statusDataEntries)
	if err != nil {
		return errors.Errorf("failed to write status to fileDB: unable to encode status file %s: %v", c.statusPath, err)
	}
	err = c.fsHandler.WriteFile(c.statusPath, stFileEntries)
	if err != nil {
		return errors.Errorf("failed to write status %s to fileDB: %v", c.statusPath, err)
	}
	return nil
}
1148353
func (database *Database) Put(key string, value interface{}) {
	database.db.Put(key, value)
}
491313
func (md *MDServerDisk) copy(config mdServerLocalConfig) mdServerLocal {
	// NOTE: observers and sessionHeads are copied shallowly on
	// purpose, so that the MD server that gets a Put will notify all
	// observers correctly no matter where they got on the list.
	log := config.MakeLogger("")
	return &MDServerDisk{config, log, md.mdServerDiskShared}
}
1178111
func (c *BufferLRU) Put(key int64, slice []byte) {
	c.mut.Lock()
	defer c.mut.Unlock()

	if c.cache == nil {
		c.actualSize = 0
		c.cache = make(map[int64]*list.Element, 1000)
		c.ll = list.New()
	}

	bufSize := FileSize(len(slice))
	if ee, ok := c.cache[key]; ok {
		oldBuf := ee.Value.(buffer)
		// in this case bufSize is a delta: new size - old size
		bufSize -= FileSize(len(oldBuf.Slice))
		c.ll.MoveToFront(ee)
		ee.Value = buffer{key, slice}
	} else {
		if bufSize > c.MaxSize {
			return
		}
		ee := c.ll.PushFront(buffer{key, slice})
		c.cache[key] = ee
	}

	c.actualSize += bufSize
	for c.actualSize > c.MaxSize {
		last := c.ll.Back()
		lastObj := last.Value.(buffer)
		lastSize := FileSize(len(lastObj.Slice))

		c.ll.Remove(last)
		delete(c.cache, lastObj.Key)
		c.actualSize -= lastSize
	}
}
1014490
func (cache *DiskBlockCacheLocal) Put(
	ctx context.Context, tlfID tlf.ID, blockID kbfsblock.ID, buf []byte,
	serverHalf kbfscrypto.BlockCryptKeyServerHalf) (err error) {
	cache.lock.Lock()
	defer cache.lock.Unlock()
	err = cache.checkCacheLocked("Block(Put)")
	if err != nil {
		return err
	}

	blockLen := len(buf)
	entry, err := cache.encodeBlockCacheEntry(buf, serverHalf)
	if err != nil {
		return err
	}
	encodedLen := int64(len(entry))
	defer func() {
		cache.log.CDebugf(ctx, "Cache Put id=%s tlf=%s bSize=%d entrySize=%d "+
			"cacheType=%s err=%+v", blockID, tlfID, blockLen, encodedLen,
			cache.cacheType, err)
	}()
	blockKey := blockID.Bytes()
	hasKey, err := cache.blockDb.Has(blockKey, nil)
	if err != nil {
		cache.log.CDebugf(ctx, "Cache Put failed due to error from "+
			"blockDb.Has: %+v", err)
		return err
	}
	if !hasKey {
		if cache.cacheType == syncCacheLimitTrackerType {
			bytesAvailable, err := cache.config.DiskLimiter().reserveBytes(
				ctx, cache.cacheType, encodedLen)
			if err != nil {
				cache.log.CWarningf(ctx, "Error obtaining space for the disk "+
					"block cache: %+v", err)
				return err
			}
			if bytesAvailable < 0 {
				return data.CachePutCacheFullError{BlockID: blockID}
			}
		} else {
			hasEnoughSpace, err := cache.evictUntilBytesAvailable(ctx, encodedLen)
			if err != nil {
				return err
			}
			if !hasEnoughSpace {
				return data.CachePutCacheFullError{BlockID: blockID}
			}
		}
		err = cache.blockDb.PutWithMeter(blockKey, entry, cache.putMeter)
		if err != nil {
			if cache.useLimiter() {
				cache.config.DiskLimiter().commitOrRollback(ctx,
					cache.cacheType, encodedLen, 0, false, "")
			}
			return err
		}
		if cache.useLimiter() {
			cache.config.DiskLimiter().commitOrRollback(ctx, cache.cacheType,
				encodedLen, 0, true, "")
		}
		cache.tlfCounts[tlfID]++
		cache.priorityBlockCounts[cache.homeDirs[tlfID]]++
		cache.priorityTlfMap[cache.homeDirs[tlfID]][tlfID]++
		cache.numBlocks++
		encodedLenUint := uint64(encodedLen)
		cache.tlfSizes[tlfID] += encodedLenUint
		cache.addCurrBytes(encodedLenUint)
	}
	tlfKey := cache.tlfKey(tlfID, blockKey)
	hasKey, err = cache.tlfDb.Has(tlfKey, nil)
	if err != nil {
		cache.log.CWarningf(ctx, "Error reading from TLF cache database: %+v",
			err)
	}
	if !hasKey {
		err = cache.tlfDb.Put(tlfKey, []byte{}, nil)
		if err != nil {
			cache.log.CWarningf(ctx,
				"Error writing to TLF cache database: %+v", err)
		}
	}
	md, err := cache.getMetadataLocked(blockID, false)
	if err != nil {
		// Only set the relevant fields if we had trouble getting the metadata.
		// Initially leave TriggeredPrefetch and FinishedPrefetch as false;
		// rely on the later-called UpdateMetadata to fix it.
		md.TlfID = tlfID
		md.BlockSize = uint32(encodedLen)
		err = nil
	}
	return cache.updateMetadataLocked(ctx, blockKey, md, unmetered)
}