From 107d1113e560538d8469c233f0b5b411031ad9c7 Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Wed, 2 Aug 2023 16:15:37 +1000 Subject: [PATCH] Rename marker folders when hash changes (#3988) --- pkg/models/paths/paths_scene_markers.go | 10 +++++++--- pkg/scene/migrate_hash.go | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/pkg/models/paths/paths_scene_markers.go b/pkg/models/paths/paths_scene_markers.go index 7524c1713..340a32b28 100644 --- a/pkg/models/paths/paths_scene_markers.go +++ b/pkg/models/paths/paths_scene_markers.go @@ -16,14 +16,18 @@ func newSceneMarkerPaths(p Paths) *sceneMarkerPaths { return &sp } +func (sp *sceneMarkerPaths) GetFolderPath(checksum string) string { + return filepath.Join(sp.Markers, checksum) +} + func (sp *sceneMarkerPaths) GetVideoPreviewPath(checksum string, seconds int) string { - return filepath.Join(sp.Markers, checksum, strconv.Itoa(seconds)+".mp4") + return filepath.Join(sp.GetFolderPath(checksum), strconv.Itoa(seconds)+".mp4") } func (sp *sceneMarkerPaths) GetWebpPreviewPath(checksum string, seconds int) string { - return filepath.Join(sp.Markers, checksum, strconv.Itoa(seconds)+".webp") + return filepath.Join(sp.GetFolderPath(checksum), strconv.Itoa(seconds)+".webp") } func (sp *sceneMarkerPaths) GetScreenshotPath(checksum string, seconds int) string { - return filepath.Join(sp.Markers, checksum, strconv.Itoa(seconds)+".jpg") + return filepath.Join(sp.GetFolderPath(checksum), strconv.Itoa(seconds)+".jpg") } diff --git a/pkg/scene/migrate_hash.go b/pkg/scene/migrate_hash.go index 09b25297f..9b74e571d 100644 --- a/pkg/scene/migrate_hash.go +++ b/pkg/scene/migrate_hash.go @@ -40,6 +40,12 @@ func MigrateHash(p *paths.Paths, oldHash string, newHash string) { oldPath = scenePaths.GetInteractiveHeatmapPath(oldHash) newPath = scenePaths.GetInteractiveHeatmapPath(newHash) migrateSceneFiles(oldPath, newPath) + + // #3986 - migrate scene marker files + markerPaths := p.SceneMarkers + oldPath = markerPaths.GetFolderPath(oldHash) + newPath = markerPaths.GetFolderPath(newHash) + migrateSceneFolder(oldPath, newPath) } func migrateSceneFiles(oldName, newName string) { @@ -75,3 +81,18 @@ func migrateVttFile(vttPath, oldSpritePath, newSpritePath string) { return } } + +func migrateSceneFolder(oldName, newName string) { + oldExists, err := fsutil.DirExists(oldName) + if err != nil && !os.IsNotExist(err) { + logger.Errorf("Error checking existence of %s: %s", oldName, err.Error()) + return + } + + if oldExists { + logger.Infof("renaming %s to %s", oldName, newName) + if err := os.Rename(oldName, newName); err != nil { + logger.Errorf("error renaming %s to %s: %s", oldName, newName, err.Error()) + } + } +}