2020-05-11 20:57:46 +02:00
|
|
|
// 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
|
|
|
|
|
2020-05-29 15:08:11 +02:00
|
|
|
// temp is the context key for temp struct.
|
2020-05-11 20:57:46 +02:00
|
|
|
const tempKey key = 0
|
|
|
|
|
|
|
|
type temp struct {
|
|
|
|
inmemory bool
|
|
|
|
directory string
|
|
|
|
}
|
|
|
|
|
2020-05-29 15:08:11 +02:00
|
|
|
// WithTempData creates context with information how store temporary data, in memory or on disk.
|
2020-05-11 20:57:46 +02:00
|
|
|
func WithTempData(ctx context.Context, directory string, inmemory bool) context.Context {
|
|
|
|
temp := temp{
|
|
|
|
inmemory: inmemory,
|
|
|
|
directory: directory,
|
|
|
|
}
|
|
|
|
return context.WithValue(ctx, tempKey, temp)
|
|
|
|
}
|
|
|
|
|
2020-05-29 15:08:11 +02:00
|
|
|
// GetTempData returns if temporary data should be stored in memory or on disk.
|
2020-05-11 20:57:46 +02:00
|
|
|
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
|
|
|
|
}
|