ente/cli/pkg/cli.go
Trekky12 8056720e23
Add possibility to define cli download tmp path with env variable (#3298)
## Description
When the /tmp folder is tmpfs the size is restricted and the download
failes when this tmp folder is full.
This PR introduces a enviroment variable to set the tmp download folder.
2024-09-17 08:55:11 +05:30

44 lines
895 B
Go

package pkg
import (
"fmt"
"github.com/ente-io/cli/internal/api"
"github.com/ente-io/cli/pkg/secrets"
bolt "go.etcd.io/bbolt"
"os"
"path/filepath"
)
type ClICtrl struct {
Client *api.Client
DB *bolt.DB
KeyHolder *secrets.KeyHolder
tempFolder string
}
func (c *ClICtrl) Init() error {
tempPath := filepath.Join(GetCLITempPath(), "ente-download")
// create temp folder if not exists
if _, err := os.Stat(tempPath); os.IsNotExist(err) {
err = os.Mkdir(tempPath, 0755)
if err != nil {
return err
}
}
c.tempFolder = tempPath
return c.DB.Update(func(tx *bolt.Tx) error {
_, err := tx.CreateBucketIfNotExists([]byte(AccBucket))
if err != nil {
return fmt.Errorf("create bucket: %s", err)
}
return nil
})
}
func GetCLITempPath() (string) {
if os.Getenv("ENTE_CLI_TMP_PATH") != "" {
return os.Getenv("ENTE_CLI_TMP_PATH")
}
return os.TempDir()
}