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)
|
ramDurationStr = strings.TrimSpace(ramDurationStr)
|
||||||
if ramDurationStr == "" {
|
if ramDurationStr == "" {
|
||||||
config.RamCache.Duration = defaultConfig.RamCache.Duration
|
config.RamCache.Duration = defaultConfig.RamCache.Duration
|
||||||
config.RamCacheEnabled = true
|
config.RamCacheEnabled = defaultConfig.RamCacheEnabled
|
||||||
} else if ramDurationStr == "0h" {
|
|
||||||
config.RamCacheEnabled = false
|
|
||||||
} else {
|
} else {
|
||||||
ramDuration, err := time.ParseDuration(ramDurationStr)
|
ramDuration, err := time.ParseDuration(ramDurationStr)
|
||||||
if err != nil {
|
if err != nil || ramDuration == 0 {
|
||||||
printWarn("Invalid duration, using default (6h).")
|
printWarn("Invalid duration, using default (6h).")
|
||||||
config.RamCache.Duration = defaultConfig.RamCache.Duration
|
config.RamCache.Duration = defaultConfig.RamCache.Duration
|
||||||
config.RamCacheEnabled = true
|
config.RamCacheEnabled = defaultConfig.RamCacheEnabled
|
||||||
} else {
|
} else {
|
||||||
config.RamCache.Duration = ramDuration
|
config.RamCache.Duration = ramDuration
|
||||||
config.RamCacheEnabled = true
|
config.RamCacheEnabled = true
|
||||||
|
@ -151,18 +149,16 @@ func createConfig() error {
|
||||||
driveDurationStr = strings.TrimSpace(driveDurationStr)
|
driveDurationStr = strings.TrimSpace(driveDurationStr)
|
||||||
if driveDurationStr == "" {
|
if driveDurationStr == "" {
|
||||||
config.DriveCache.Duration = defaultConfig.DriveCache.Duration
|
config.DriveCache.Duration = defaultConfig.DriveCache.Duration
|
||||||
config.DriveCacheEnabled = config.DriveCache.Duration > 0
|
config.DriveCacheEnabled = defaultConfig.DriveCacheEnabled
|
||||||
} else if driveDurationStr == "0h" {
|
|
||||||
config.DriveCacheEnabled = false
|
|
||||||
} else {
|
} else {
|
||||||
driveDuration, err := time.ParseDuration(driveDurationStr)
|
driveDuration, err := time.ParseDuration(driveDurationStr)
|
||||||
if err != nil {
|
if err != nil || driveDuration == 0 {
|
||||||
printWarn("Invalid duration, using default (48h).")
|
printErr("Invalid duration, using default (48h).")
|
||||||
config.DriveCache.Duration = defaultConfig.DriveCache.Duration
|
config.DriveCache.Duration = defaultConfig.DriveCache.Duration
|
||||||
config.DriveCacheEnabled = config.DriveCache.Duration > 0
|
config.DriveCacheEnabled = defaultConfig.DriveCacheEnabled
|
||||||
} else {
|
} else {
|
||||||
config.DriveCache.Duration = driveDuration
|
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.")
|
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
|
// Start periodic cleanup of expired cache files
|
||||||
if config.DriveCacheEnabled {
|
if config.DriveCacheEnabled {
|
||||||
go cleanExpiredCachedImages()
|
go cleanExpiredCachedImages()
|
||||||
|
|
Loading…
Add table
Reference in a new issue