🧱 Chunk is a download manager for slow and unstable servers
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Refactors reader of the progress directory value

+9 -10
+9 -10
progress.go
··· 18 18 19 19 // get the chunk directory under user's home directory 20 20 // TODO: make it configurable (maybe an envvar?) 21 - func getChunkDirectory(custom string) (string, error) { 22 - d := os.Getenv("CHUNK_DIR") 23 - if custom != "" { 24 - d = custom 21 + func getChunkProgressDir(dir string) (string, error) { 22 + if dir == "" { 23 + dir = os.Getenv("CHUNK_DIR") 25 24 } 26 - if d == "" { 25 + if dir == "" { 27 26 u, err := user.Current() 28 27 if err != nil { 29 28 return "", fmt.Errorf("could not get current user: %w", err) 30 29 } 31 - d = filepath.Join(u.HomeDir, DefaultChunkDir) 30 + dir = filepath.Join(u.HomeDir, DefaultChunkDir) 32 31 } 33 - if err := os.MkdirAll(d, 0755); err != nil { 34 - return "", fmt.Errorf("could not create chunk's directory %s: %w", d, err) 32 + if err := os.MkdirAll(dir, 0755); err != nil { 33 + return "", fmt.Errorf("could not create chunk's directory %s: %w", dir, err) 35 34 } 36 - return d, nil 35 + return dir, nil 37 36 } 38 37 39 38 type progress struct { ··· 157 156 } 158 157 159 158 func newProgress(path, dir string, url string, chunkSize int64, chunks int, restart bool) (*progress, error) { 160 - dir, err := getChunkDirectory(dir) 159 + dir, err := getChunkProgressDir(dir) 161 160 if err != nil { 162 161 return nil, fmt.Errorf("could not get chunk's directory: %w", err) 163 162 }