// getOrRemove gets the file with the given id. If it's expired, it will
// be removed.
768162
func (c *Cache) getOrRemove(id string) hugio.ReadSeekCloser {
	if c.maxAge == 0 {
		// No caching.
		return nil
	}

	if c.maxAge > 0 {
		fi, err := c.Fs.Stat(id)
		if err != nil {
			return nil
		}

		if c.isExpired(fi.ModTime()) {
			c.Fs.Remove(id)
			return nil
		}
	}

	f, err := c.Fs.Open(id)

	if err != nil {
		return nil
	}

	return f
}
306216
func (x *Index) Delete(c context.Context, id string) error {
	req := &pb.DeleteDocumentRequest{
		Params: &pb.DeleteDocumentParams{
			DocId:     []string{id},
			IndexSpec: &x.spec,
		},
	}
	res := &pb.DeleteDocumentResponse{}
	if err := internal.Call(c, "search", "DeleteDocument", req, res); err != nil {
		return err
	}
	if len(res.Status) != 1 {
		return fmt.Errorf("search: internal error: wrong number of results (%d)", len(res.Status))
	}
	if s := res.Status[0]; s.GetCode() != pb.SearchServiceError_OK {
		return fmt.Errorf("search: %s: %s", s.GetCode(), s.GetErrorDetail())
	}
	return nil
}
681274
func NodeRemove(id string) error {
	return mgr.Do(func(ctx context.Context, cli *client.Client) (err error) {
		return cli.NodeRemove(ctx, id, types.NodeRemoveOptions{})
	})
}
52071
func (ts *Store) remove(id string) error {
	treepath := ts.GetPath(id)
	// If tree path doesn't exist we're done
	_, err := os.Stat(treepath)
	if err != nil && os.IsNotExist(err) {
		return nil
	}
	if err != nil {
		return errwrap.Wrap(errors.New("failed to open tree store directory"), err)
	}

	renderedFilePath := filepath.Join(treepath, renderedfilename)
	// The "rendered" flag file should be the firstly removed file. So if
	// the removal ends with some error leaving some stale files IsRendered()
	// will return false.
	_, err = os.Stat(renderedFilePath)
	if err != nil && !os.IsNotExist(err) {
		return err
	}
	if !os.IsNotExist(err) {
		err := os.Remove(renderedFilePath)
		// Ensure that the treepath directory is fsynced after removing the
		// "rendered" flag file
		f, err := os.Open(treepath)
		if err != nil {
			return errwrap.Wrap(errors.New("failed to open tree store directory"), err)
		}
		defer f.Close()
		err = f.Sync()
		if err != nil {
			return errwrap.Wrap(errors.New("failed to sync tree store directory"), err)
		}
	}

	// Ignore error retrieving image hash
	key, _ := ts.GetImageHash(id)

	if err := os.RemoveAll(treepath); err != nil {
		return err
	}

	if key != "" {
		return ts.store.UpdateTreeStoreSize(key, 0)
	}

	return nil
}
818737
func (this *RedisStore) Delete(id string) error {
	key := id
	if this.opts.KeyPrefix != "" {
		key = this.opts.KeyPrefix + ":" + id
	}
	_, err := this.conn.Do("DEL", key)
	if err != nil {
		return err
	}
	return nil
}
640486
func (c *FindCache) Purge(orgId uint32) {
	c.RLock()
	cache, ok := c.cache[orgId]
	c.RUnlock()
	if !ok {
		return
	}
	cache.Purge()
}
251321
func (mj *mirrorJob) doRemove(sURLs URLs) URLs {
	if mj.isFake {
		return sURLs.WithError(nil)
	}

	// Construct proper path with alias.
	targetWithAlias := filepath.Join(sURLs.TargetAlias, sURLs.TargetContent.URL.Path)
	clnt, pErr := newClient(targetWithAlias)
	if pErr != nil {
		return sURLs.WithError(pErr)
	}

	contentCh := make(chan *clientContent, 1)
	contentCh <- &clientContent{URL: *newClientURL(sURLs.TargetContent.URL.Path)}
	close(contentCh)
	isRemoveBucket := false
	errorCh := clnt.Remove(false, isRemoveBucket, contentCh)
	for pErr := range errorCh {
		if pErr != nil {
			switch pErr.ToGoError().(type) {
			case PathInsufficientPermission:
				// Ignore Permission error.
				continue
			}
			return sURLs.WithError(pErr)
		}
	}

	return sURLs.WithError(nil)
}
1136470
func (s *UpdateSecretVersionStageInput) SetRemoveFromVersionId(v string) *UpdateSecretVersionStageInput {
	s.RemoveFromVersionId = &v
	return s
}
734774
func (c *Cache) Get(id string) (ItemInfo, io.ReadCloser, error) {
	id = cleanID(id)

	c.nlocker.Lock(id)
	defer c.nlocker.Unlock(id)

	info := ItemInfo{Name: id}

	r := c.getOrRemove(id)

	return info, r, nil
}
548255
func (_m *APIClient) ImageRemove(ctx context.Context, _a1 string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
	ret := _m.Called(ctx, _a1, options)

	var r0 []types.ImageDeleteResponseItem
	if rf, ok := ret.Get(0).(func(context.Context, string, types.ImageRemoveOptions) []types.ImageDeleteResponseItem); ok {
		r0 = rf(ctx, _a1, options)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).([]types.ImageDeleteResponseItem)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(context.Context, string, types.ImageRemoveOptions) error); ok {
		r1 = rf(ctx, _a1, options)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
794252
func (s *ServerRPC) ImageRemove(ctx context.Context, req *types.ImageRemoveRequest) (*types.ImageRemoveResponse, error) {
	resp, err := s.daemon.CmdImageDelete(req.Image, req.Force, req.Prune)
	if err != nil {
		return nil, err
	}

	return &types.ImageRemoveResponse{
		Images: resp,
	}, nil
}
863041
func (b *backups) Get(id string) (*Metadata, io.ReadCloser, error) {
	if strings.Contains(id, TempFilename) {
		return b.getArchiveFromFilename(id)
	}
	rawmeta, archiveFile, err := b.storage.Get(id)
	if err != nil {
		return nil, nil, errors.Trace(err)
	}

	meta, ok := rawmeta.(*Metadata)
	if !ok {
		return nil, nil, errors.New("did not get a backups.Metadata value from storage")
	}

	return meta, archiveFile, nil
}
619765
func (s *grpcAPIService) HistoryRemove(ctx context.Context, req *HistoryRemoveRequest) (*HistoryRemoveResponse, error) {
	return s.api.HistoryRemove(ctx, req), nil
}
897471
func (c *Client) Detach(storageIds []string, force *bool, maxWait *time.Duration) ([]params.ErrorResult, error) {
	results := params.ErrorResults{}
	ids := make([]params.StorageAttachmentId, len(storageIds))
	for i, id := range storageIds {
		if !names.IsValidStorage(id) {
			return nil, errors.NotValidf("storage ID %q", id)
		}
		ids[i] = params.StorageAttachmentId{
			StorageTag: names.NewStorageTag(id).String(),
		}
	}
	var args interface{}
	var method string
	if c.BestAPIVersion() < 6 {
		method = "Detach"
		args = params.StorageAttachmentIds{ids}
	} else {
		method = "DetachStorage"
		args = params.StorageDetachmentParams{
			StorageIds: params.StorageAttachmentIds{ids},
			Force:      force,
			MaxWait:    maxWait,
		}
	}
	if err := c.facade.FacadeCall(method, args, &results); err != nil {
		return nil, errors.Trace(err)
	}
	if len(results.Results) != len(storageIds) {
		return nil, errors.Errorf(
			"expected %d result(s), got %d",
			len(storageIds), len(results.Results),
		)
	}
	return results.Results, nil
}
540115
func (f *Facade) CheckRemoveRegistryImage(ctx datastore.Context, imageID string) error {
	if len(imageID) > 0 {
		logger := log.WithField("imageid", imageID)
		if count, err := f.serviceStore.GetServiceCountByImage(ctx, imageID); err != nil {
			logger.WithError(err).Error("Error getting service count by imageID")
			return err
		} else if count == 0 {
			logger.Info("Removing image from the image registry")
			if err := f.registryStore.Delete(ctx, imageID); err != nil {
				logger.WithError(err).Error("Unable to remove unused image from the image registry")
				return err
			}
		}
	}
	return nil
}
1220608
func (c *Client) LinkRemove(bucket, key, lbucket, lkey string) error {
	obj, err := c.FetchObject(bucket, key)
	if err != nil {
		return err
	}

	if len(obj.GetContent()) == 0 {
		return ErrNoContent
	}

	for i, k := range obj.GetContent()[0].GetLinks() {
		if string(k.GetBucket()) == lbucket && string(k.GetKey()) == lkey {
			obj.Content[0].Links[i] = obj.Content[0].Links[len(obj.Content[0].Links)-1]
			obj.Content[0].Links = obj.Content[0].Links[0 : len(obj.Content[0].Links)-1]
			break
		}
	}

	if _, err := c.StoreObject(bucket, key, obj.GetContent()[0]); err != nil {
		return err
	}

	return nil
}
595784
func (fs RouteFileStore) Remove(id string) bool {
	if _, err := os.Stat(fs.Filename(id)); err == nil {
		if err := os.Remove(fs.Filename(id)); err != nil {
			return true
		}
	}
	return false
}