photoprism/internal/photoprism/delete.go
Michael Mayer 92e6c4fe1e Download: Add Disabled, Originals, MediaRaw & MediaSidecar Flags #2234
Extends DownloadSettings with 4 additional options:
- Name: File name pattern for downloaded files (existed)
- Disabled: Disables downloads
- Originals: Only download files stored in "originals" folder
- MediaRaw: Include RAW image files
- MediaSidecar: Include metadata sidecar files (JSON, XMP, YAML)
2022-04-15 09:42:07 +02:00

55 lines
1.5 KiB
Go

package photoprism
import (
"os"
"path/filepath"
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/pkg/clean"
"github.com/photoprism/photoprism/pkg/fs"
)
// Delete permanently removes a photo and all its files.
func Delete(p entity.Photo) error {
yamlFileName := p.YamlFileName(Config().OriginalsPath(), Config().SidecarPath())
// Permanently remove photo from index.
files, err := p.DeletePermanently()
if err != nil {
return err
}
// Delete related files.
for _, file := range files {
fileName := FileName(file.FileRoot, file.FileName)
log.Debugf("delete: removing file %s", clean.Log(file.FileName))
if f, err := NewMediaFile(fileName); err == nil {
if sidecarJson := f.SidecarJsonName(); fs.FileExists(sidecarJson) {
log.Debugf("delete: removing json sidecar %s", clean.Log(filepath.Base(sidecarJson)))
logWarn("delete", os.Remove(sidecarJson))
}
if exifJson, err := f.ExifToolJsonName(); err == nil && fs.FileExists(exifJson) {
log.Debugf("delete: removing exiftool sidecar %s", clean.Log(filepath.Base(exifJson)))
logWarn("delete", os.Remove(exifJson))
}
logWarn("delete", f.RemoveSidecars())
}
if fs.FileExists(fileName) {
logWarn("delete", os.Remove(fileName))
}
}
// Remove sidecar backup.
if fs.FileExists(yamlFileName) {
log.Debugf("delete: removing yaml sidecar %s", clean.Log(filepath.Base(yamlFileName)))
logWarn("delete", os.Remove(yamlFileName))
}
return nil
}