added cache folder check
This commit is contained in:
parent
44e9d3356f
commit
ff84d49ff3
2 changed files with 16 additions and 12 deletions
20
config.go
20
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
8
init.go
8
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()
|
||||
|
|
Loading…
Add table
Reference in a new issue