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:
parent
8d2932dc4d
commit
9787fd570f
|
@ -1,6 +1,7 @@
|
||||||
package scanner
|
package scanner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
@ -231,10 +232,14 @@ func getMediaType(path string) (*MediaType, error) {
|
||||||
|
|
||||||
ext := filepath.Ext(path)
|
ext := filepath.Ext(path)
|
||||||
|
|
||||||
fileExtType := fileExtensions[strings.ToLower(ext)]
|
fileExtType, found := fileExtensions[strings.ToLower(ext)]
|
||||||
|
|
||||||
|
if found {
|
||||||
if fileExtType.isSupported() {
|
if fileExtType.isSupported() {
|
||||||
return &fileExtType, nil
|
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
|
// If extension was not recognized try to read file header
|
||||||
|
|
|
@ -319,7 +319,7 @@ func processRawSideCar(tx *sql.Tx, imageData *EncodeMediaData, highResURL *model
|
||||||
currentSideCarPath := scanForSideCarFile(photo.Path)
|
currentSideCarPath := scanForSideCarFile(photo.Path)
|
||||||
|
|
||||||
if currentSideCarPath != nil {
|
if currentSideCarPath != nil {
|
||||||
currentFileHash := hashSideCarFile(currentSideCarPath)
|
currentFileHash = hashSideCarFile(currentSideCarPath)
|
||||||
if photo.SideCarHash == nil || *photo.SideCarHash != *currentFileHash {
|
if photo.SideCarHash == nil || *photo.SideCarHash != *currentFileHash {
|
||||||
sideCarFileHasChanged = true
|
sideCarFileHasChanged = true
|
||||||
}
|
}
|
||||||
|
@ -354,7 +354,7 @@ func processRawSideCar(tx *sql.Tx, imageData *EncodeMediaData, highResURL *model
|
||||||
// save new side car hash
|
// save new side car hash
|
||||||
_, err = tx.Exec("UPDATE media SET side_car_hash = ?, side_car_path = ? WHERE media_id = ?", currentFileHash, currentSideCarPath, photo.MediaID)
|
_, err = tx.Exec("UPDATE media SET side_car_hash = ?, side_car_path = ? WHERE media_id = ?", currentFileHash, currentSideCarPath, photo.MediaID)
|
||||||
if err != nil {
|
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
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue