mirror of
https://github.com/makew0rld/amfora.git
synced 2025-02-02 15:07:34 -05:00
🐛 Use custom downloads dir
This commit is contained in:
parent
a0ae0ca835
commit
8412b211b6
@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Single quotes are used in the default config for commands and paths so that Windows paths with backslashes will be parsed correctly
|
||||
- Downloading now uses proxies when appropriate
|
||||
- User-entered URLs with invalid characters will be percent-encoded (#138)
|
||||
- Custom downloads dir is actually used (#148)
|
||||
|
||||
|
||||
## [1.6.0] - 2020-11-04
|
||||
|
@ -157,43 +157,6 @@ func Init() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// *** Downloads paths, setup, and creation ***
|
||||
|
||||
// Setup downloads dir
|
||||
if viper.GetString("a-general.downloads") == "" {
|
||||
// Find default Downloads dir
|
||||
// This seems to work for all OSes?
|
||||
if userdirs.Download == "" {
|
||||
DownloadsDir = filepath.Join(home, "Downloads")
|
||||
} else {
|
||||
DownloadsDir = userdirs.Download
|
||||
}
|
||||
// Create it just in case
|
||||
err = os.MkdirAll(DownloadsDir, 0755)
|
||||
if err != nil {
|
||||
return fmt.Errorf("downloads path could not be created: %s", DownloadsDir)
|
||||
}
|
||||
} else {
|
||||
// Validate path
|
||||
dDir := viper.GetString("a-general.downloads")
|
||||
di, err := os.Stat(dDir)
|
||||
if err == nil {
|
||||
if !di.IsDir() {
|
||||
return fmt.Errorf("downloads path specified is not a directory: %s", dDir)
|
||||
}
|
||||
} else if os.IsNotExist(err) {
|
||||
// Try to create path
|
||||
err = os.MkdirAll(dDir, 0755)
|
||||
if err != nil {
|
||||
return fmt.Errorf("downloads path could not be created: %s", dDir)
|
||||
}
|
||||
} else {
|
||||
// Some other error
|
||||
return fmt.Errorf("couldn't access downloads directory: %s", dDir)
|
||||
}
|
||||
DownloadsDir = dDir
|
||||
}
|
||||
|
||||
// *** Setup vipers ***
|
||||
|
||||
TofuStore.SetConfigFile(tofuDBPath)
|
||||
@ -247,6 +210,42 @@ func Init() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// *** Downloads paths, setup, and creation ***
|
||||
|
||||
// Setup downloads dir
|
||||
if viper.GetString("a-general.downloads") == "" {
|
||||
// Find default Downloads dir
|
||||
if userdirs.Download == "" {
|
||||
DownloadsDir = filepath.Join(home, "Downloads")
|
||||
} else {
|
||||
DownloadsDir = userdirs.Download
|
||||
}
|
||||
// Create it just in case
|
||||
err = os.MkdirAll(DownloadsDir, 0755)
|
||||
if err != nil {
|
||||
return fmt.Errorf("downloads path could not be created: %s", DownloadsDir)
|
||||
}
|
||||
} else {
|
||||
// Validate path
|
||||
dDir := viper.GetString("a-general.downloads")
|
||||
di, err := os.Stat(dDir)
|
||||
if err == nil {
|
||||
if !di.IsDir() {
|
||||
return fmt.Errorf("downloads path specified is not a directory: %s", dDir)
|
||||
}
|
||||
} else if os.IsNotExist(err) {
|
||||
// Try to create path
|
||||
err = os.MkdirAll(dDir, 0755)
|
||||
if err != nil {
|
||||
return fmt.Errorf("downloads path could not be created: %s", dDir)
|
||||
}
|
||||
} else {
|
||||
// Some other error
|
||||
return fmt.Errorf("couldn't access downloads directory: %s", dDir)
|
||||
}
|
||||
DownloadsDir = dDir
|
||||
}
|
||||
|
||||
// Setup cache from config
|
||||
cache.SetMaxSize(viper.GetInt("cache.max_size"))
|
||||
cache.SetMaxPages(viper.GetInt("cache.max_pages"))
|
||||
|
Loading…
x
Reference in New Issue
Block a user