From d5227a4ce323beb23ffcdcd95554ed9bc03ffe7b Mon Sep 17 00:00:00 2001 From: viktorstrate Date: Thu, 16 Apr 2020 11:23:34 +0200 Subject: [PATCH] Make sure that photo directory for user exists If user directory doesn't exist anymore report an error notification. --- api/scanner/album_scanner.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/api/scanner/album_scanner.go b/api/scanner/album_scanner.go index cdebd115..5788b794 100644 --- a/api/scanner/album_scanner.go +++ b/api/scanner/album_scanner.go @@ -99,6 +99,17 @@ func ScanUser(database *sql.DB, userId int) error { func scan(database *sql.DB, user *models.User) { + // Check if user directory exists on the file system + if _, err := os.Stat(user.RootPath); err != nil { + if os.IsNotExist(err) { + ScannerError("Photo directory for user '%s' does not exist '%s'\n", user.Username, user.RootPath) + } else { + ScannerError("Could not read photo directory for user '%s': %s\n", user.Username, user.RootPath) + } + + return + } + notifyKey := utils.GenerateToken() processKey := utils.GenerateToken() notifyThrottle := utils.NewThrottle(500 * time.Millisecond)