diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bb1192..bdf8ca7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/config/config.go b/config/config.go index 26f5938..7935799 100644 --- a/config/config.go +++ b/config/config.go @@ -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"))