1
Fork 0

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
This commit is contained in:
viktorstrate 2020-11-22 23:42:42 +01:00
parent 8d2932dc4d
commit 9787fd570f
2 changed files with 10 additions and 5 deletions

View File

@ -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

View File

@ -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