From 9787fd570f6833d5dc4a05defafd0bfce49fe19b Mon Sep 17 00:00:00 2001 From: viktorstrate Date: Sun, 22 Nov 2020 23:42:42 +0100 Subject: [PATCH] Cleanup and bugfixes - Fix bug where unsupported media would be wrongly classified - Fix bug where sidecar hash wouldn't be updated - Replace error reporting hash with path, to avoid potential null pointer exceptions --- api/scanner/media_type.go | 11 ++++++++--- api/scanner/process_photo.go | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/api/scanner/media_type.go b/api/scanner/media_type.go index 08819611..5acfca59 100644 --- a/api/scanner/media_type.go +++ b/api/scanner/media_type.go @@ -1,6 +1,7 @@ package scanner import ( + "fmt" "io" "log" "os" @@ -231,10 +232,14 @@ func getMediaType(path string) (*MediaType, error) { ext := filepath.Ext(path) - fileExtType := fileExtensions[strings.ToLower(ext)] + fileExtType, found := fileExtensions[strings.ToLower(ext)] - if fileExtType.isSupported() { - return &fileExtType, nil + if found { + if fileExtType.isSupported() { + return &fileExtType, nil + } else { + return nil, errors.New(fmt.Sprintf("unsupported file type '%s' (%s)", ext, fileExtType)) + } } // If extension was not recognized try to read file header diff --git a/api/scanner/process_photo.go b/api/scanner/process_photo.go index bce18938..4a5ba70a 100644 --- a/api/scanner/process_photo.go +++ b/api/scanner/process_photo.go @@ -319,7 +319,7 @@ func processRawSideCar(tx *sql.Tx, imageData *EncodeMediaData, highResURL *model currentSideCarPath := scanForSideCarFile(photo.Path) if currentSideCarPath != nil { - currentFileHash := hashSideCarFile(currentSideCarPath) + currentFileHash = hashSideCarFile(currentSideCarPath) if photo.SideCarHash == nil || *photo.SideCarHash != *currentFileHash { sideCarFileHasChanged = true } @@ -354,7 +354,7 @@ func processRawSideCar(tx *sql.Tx, imageData *EncodeMediaData, highResURL *model // save new side car hash _, err = tx.Exec("UPDATE media SET side_car_hash = ?, side_car_path = ? WHERE media_id = ?", currentFileHash, currentSideCarPath, photo.MediaID) if err != nil { - return errors.Wrapf(err, "could not update side car hash (%d, %s)", photo.MediaID, *currentFileHash) + return errors.Wrapf(err, "could not update side car hash for media: %s", photo.Path) } } return nil