Skip to content

Commit

Permalink
Rename marker folders when hash changes (#3988)
Browse files Browse the repository at this point in the history
  • Loading branch information
WithoutPants authored Aug 2, 2023
1 parent bd28aa6 commit 107d111
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/models/paths/paths_scene_markers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
21 changes: 21 additions & 0 deletions pkg/scene/migrate_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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())
}
}
}

0 comments on commit 107d111

Please sign in to comment.