diff --git a/config.go b/config.go index b090b0a..c3aec6b 100644 --- a/config.go +++ b/config.go @@ -115,15 +115,13 @@ func createConfig() error { ramDurationStr = strings.TrimSpace(ramDurationStr) if ramDurationStr == "" { config.RamCache.Duration = defaultConfig.RamCache.Duration - config.RamCacheEnabled = true - } else if ramDurationStr == "0h" { - config.RamCacheEnabled = false + config.RamCacheEnabled = defaultConfig.RamCacheEnabled } else { ramDuration, err := time.ParseDuration(ramDurationStr) - if err != nil { + if err != nil || ramDuration == 0 { printWarn("Invalid duration, using default (6h).") config.RamCache.Duration = defaultConfig.RamCache.Duration - config.RamCacheEnabled = true + config.RamCacheEnabled = defaultConfig.RamCacheEnabled } else { config.RamCache.Duration = ramDuration config.RamCacheEnabled = true @@ -151,18 +149,16 @@ func createConfig() error { driveDurationStr = strings.TrimSpace(driveDurationStr) if driveDurationStr == "" { config.DriveCache.Duration = defaultConfig.DriveCache.Duration - config.DriveCacheEnabled = config.DriveCache.Duration > 0 - } else if driveDurationStr == "0h" { - config.DriveCacheEnabled = false + config.DriveCacheEnabled = defaultConfig.DriveCacheEnabled } else { driveDuration, err := time.ParseDuration(driveDurationStr) - if err != nil { - printWarn("Invalid duration, using default (48h).") + if err != nil || driveDuration == 0 { + printErr("Invalid duration, using default (48h).") config.DriveCache.Duration = defaultConfig.DriveCache.Duration - config.DriveCacheEnabled = config.DriveCache.Duration > 0 + config.DriveCacheEnabled = defaultConfig.DriveCacheEnabled } else { config.DriveCache.Duration = driveDuration - config.DriveCacheEnabled = config.DriveCache.Duration > 0 + config.DriveCacheEnabled = true } } diff --git a/init.go b/init.go index de6f1cb..0e86684 100644 --- a/init.go +++ b/init.go @@ -70,6 +70,14 @@ func main() { printInfo("Node client is disabled.") } + // Check if the cache directory exists when caching is enabled + if config.DriveCacheEnabled { + if _, err := os.Stat(config.DriveCache.Path); os.IsNotExist(err) { + printErr("Error: Drive cache is enabled, but cache directory '%s' does not exist.\n", config.DriveCache.Path) + os.Exit(1) // Exit with a non-zero status to indicate an error + } + } + // Start periodic cleanup of expired cache files if config.DriveCacheEnabled { go cleanExpiredCachedImages()