rclone/vendor/storj.io/common/fpath/temp_data.go
Caleb Case e7bd392a69 backend/tardigrade: Upgrade to uplink v1.0.6
This fixes an important bug with listing that affects users with more
than 500 objects in a listing operation.
2020-05-29 18:00:08 +01:00

39 lines
975 B
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
// TODO maybe there is better place for this
package fpath
import "context"
// The key type is unexported to prevent collisions with context keys defined in
// other packages.
type key int
// temp is the context key for temp struct.
const tempKey key = 0
type temp struct {
inmemory bool
directory string
}
// WithTempData creates context with information how store temporary data, in memory or on disk.
func WithTempData(ctx context.Context, directory string, inmemory bool) context.Context {
temp := temp{
inmemory: inmemory,
directory: directory,
}
return context.WithValue(ctx, tempKey, temp)
}
// GetTempData returns if temporary data should be stored in memory or on disk.
func GetTempData(ctx context.Context) (string, bool, bool) {
tempValue, ok := ctx.Value(tempKey).(temp)
if !ok {
return "", false, false
}
return tempValue.directory, tempValue.inmemory, ok
}