Skip to content

Commit

Permalink
fix: improve error handling in directory monitoring and add nil check…
Browse files Browse the repository at this point in the history
… for Redis client in thumbnail verification
  • Loading branch information
PlusOne committed Dec 31, 2024
1 parent 09fee7f commit 02c0a8f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2839,19 +2839,19 @@ func monitorDirectoryChanges(dir string) {
for {
select {
case event, ok := <-watcher.Events:
if !ok {
if (!ok) {
return
}
if event.Op&fsnotify.Create == fsnotify.Create || event.Op&fsnotify.Remove == fsnotify.Remove {
if (event.Op&fsnotify.Create == fsnotify.Create || event.Op&fsnotify.Remove == fsnotify.Remove) {
log.Infof("Directory change detected: %s", event.String())
// Update caches and indices
err := precacheStoragePath(dir)
if err != nil {
if (err != nil) {
log.Error("Failed to update precache after directory change:", err)
}
}
case err, ok := <-watcher.Errors:
if !ok {
if (!ok) {
return
}
log.Error("Directory watcher error:", err)
Expand Down Expand Up @@ -3132,6 +3132,12 @@ func handleThumbnails(w http.ResponseWriter, r *http.Request) {

// verifyAndRepairThumbnails verifies the integrity of thumbnail files and repairs them if necessary
func verifyAndRepairThumbnails(thumbnailPaths []string, redisClient *redis.Client, originalDir string) {
// Check if redisClient is nil
if redisClient == nil {
log.Warn("Redis client is nil. Skipping thumbnail verification and repair.")
return
}

// Check if thumbnailPaths is nil or empty
if len(thumbnailPaths) == 0 {
log.Error("Thumbnail paths are nil or empty. Nothing to verify or repair.")
Expand Down

0 comments on commit 02c0a8f

Please sign in to comment.