Use temporary storage while the client is streaming the file to GARM. This ensures that while uploading, we don't lock the blob database. On slow connections this would mean that no readers would be able to access the db while data was being written to it via the upload process. By saving the file to a temporary location and only after we receive the entire thing, add it to the DB, we significantly reduce the time we need to keep the DB locked. Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
22 lines
328 B
Go
22 lines
328 B
Go
package util
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
func getTempDir(baseDir string) (string, error) {
|
|
dir := baseDir
|
|
if baseDir == "" {
|
|
envTmp := os.Getenv("TEMP")
|
|
if envTmp == "" {
|
|
envTmp = os.Getenv("TMP")
|
|
}
|
|
dir = envTmp
|
|
}
|
|
|
|
if dir == "" {
|
|
return "", fmt.Errorf("failed to determine destination dir")
|
|
}
|
|
return dir, nil
|
|
}
|