From 72849bcc95eb1fe9c85da8de954d3ef8969125e4 Mon Sep 17 00:00:00 2001 From: makeworld Date: Thu, 24 Dec 2020 16:54:06 -0500 Subject: [PATCH] Re-add temp downloads dir init, in lower place --- config/config.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/config/config.go b/config/config.go index 54fcf98..7c509d0 100644 --- a/config/config.go +++ b/config/config.go @@ -298,6 +298,36 @@ func Init() error { DownloadsDir = dDir } + // Setup temporary downloads dir + if viper.GetString("a-general.temp_downloads") == "" { + TempDownloadsDir = filepath.Join(os.TempDir(), "amfora_temp") + + // Make sure it exists + err = os.MkdirAll(TempDownloadsDir, 0755) + if err != nil { + return fmt.Errorf("temp downloads path could not be created: %s", TempDownloadsDir) + } + } else { + // Validate path + dDir := viper.GetString("a-general.temp_downloads") + di, err := os.Stat(dDir) + if err == nil { + if !di.IsDir() { + return fmt.Errorf("temp 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("temp downloads path could not be created: %s", dDir) + } + } else { + // Some other error + return fmt.Errorf("couldn't access temp downloads directory: %s", dDir) + } + TempDownloadsDir = dDir + } + // Setup cache from config cache.SetMaxSize(viper.GetInt("cache.max_size")) cache.SetMaxPages(viper.GetInt("cache.max_pages"))