···66 "fmt"
77 "log/slog"
88 "os"
99- "os/user"
109 "path/filepath"
1110 "sync"
1211 "sync/atomic"
1212+1313+ gap "github.com/muesli/go-app-paths"
1314)
14151516// DefaultChunkDir is the directory where Chunk keeps track of each chunk
1616-// downloaded of each file. It us created under the user's home directory by
1717-// default. It can be replaced by the environment variable CHUNK_DIR.
1818-const DefaultChunkDir = ".chunk"
1717+// downloaded of each file. It us created under the user's cache directory
1818+// by default.
1919+// It can be replaced by a full path in the environment variable CHUNK_DIR.
2020+const DefaultChunkDir = "chunk"
19212022// get the chunk directory under user's home directory or using the envvar
2123func getChunkProgressDir(dir string) (string, error) {
···2325 dir = os.Getenv("CHUNK_DIR")
2426 }
2527 if dir == "" {
2626- u, err := user.Current()
2828+ c, err := gap.NewScope(gap.User, "app").CacheDir()
2729 if err != nil {
2828- return "", fmt.Errorf("could not get current user: %w", err)
3030+ return "", fmt.Errorf("error getting user home directory: %w", err)
2931 }
3030- dir = filepath.Join(u.HomeDir, DefaultChunkDir)
3232+ dir = filepath.Join(c, DefaultChunkDir)
3133 }
3234 if err := os.MkdirAll(dir, 0755); err != nil {
3335 return "", fmt.Errorf("could not create chunk's directory %s: %w", dir, err)