mirror of https://github.com/stashapp/stash.git
Migrate vtt contents when hash changes (#2554)
This commit is contained in:
parent
1a6f5619ae
commit
36aa51a187
|
@ -1,6 +1,8 @@
|
|||
package scene
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
|
@ -35,13 +37,14 @@ func MigrateHash(p *paths.Paths, oldHash string, newHash string) {
|
|||
newPath = scenePaths.GetTranscodePath(newHash)
|
||||
migrateSceneFiles(oldPath, newPath)
|
||||
|
||||
oldPath = scenePaths.GetSpriteVttFilePath(oldHash)
|
||||
newPath = scenePaths.GetSpriteVttFilePath(newHash)
|
||||
migrateSceneFiles(oldPath, newPath)
|
||||
oldVttPath := scenePaths.GetSpriteVttFilePath(oldHash)
|
||||
newVttPath := scenePaths.GetSpriteVttFilePath(newHash)
|
||||
migrateSceneFiles(oldVttPath, newVttPath)
|
||||
|
||||
oldPath = scenePaths.GetSpriteImageFilePath(oldHash)
|
||||
newPath = scenePaths.GetSpriteImageFilePath(newHash)
|
||||
migrateSceneFiles(oldPath, newPath)
|
||||
migrateVttFile(newVttPath, oldPath, newPath)
|
||||
|
||||
oldPath = scenePaths.GetInteractiveHeatmapPath(oldHash)
|
||||
newPath = scenePaths.GetInteractiveHeatmapPath(newHash)
|
||||
|
@ -62,3 +65,22 @@ func migrateSceneFiles(oldName, newName string) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// #2481: migrate vtt file contents in addition to renaming
|
||||
func migrateVttFile(vttPath, oldSpritePath, newSpritePath string) {
|
||||
contents, err := ioutil.ReadFile(vttPath)
|
||||
if err != nil {
|
||||
logger.Errorf("Error reading %s for vtt migration: %v", vttPath, err)
|
||||
return
|
||||
}
|
||||
|
||||
oldSpriteBasename := filepath.Base(oldSpritePath)
|
||||
newSpriteBasename := filepath.Base(newSpritePath)
|
||||
|
||||
contents = bytes.ReplaceAll(contents, []byte(oldSpriteBasename), []byte(newSpriteBasename))
|
||||
|
||||
if err := ioutil.WriteFile(vttPath, contents, 0644); err != nil {
|
||||
logger.Errorf("Error writing %s for vtt migration: %v", vttPath, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue