Add move files external interface (#3557)

* Add moveFiles graphql mutation
* Move library resolution code into config
* Implement file moving
* Log if old file not removed in SafeMove
* Ensure extensions are consistent
* Don't allow overwriting existing files
This commit is contained in:
WithoutPants
2023-03-22 07:57:26 +11:00
committed by GitHub
parent f6387c1018
commit 09c724b8d5
12 changed files with 436 additions and 50 deletions

View File

@@ -7,6 +7,7 @@ import (
"io/fs"
"os"
"github.com/stashapp/stash/pkg/fsutil"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/txn"
)
@@ -15,10 +16,10 @@ const deleteFileSuffix = ".delete"
// RenamerRemover provides access to the Rename and Remove functions.
type RenamerRemover interface {
Rename(oldpath, newpath string) error
Renamer
Remove(name string) error
RemoveAll(path string) error
Stat(name string) (fs.FileInfo, error)
Statter
}
type renamerRemoverImpl struct {
@@ -44,6 +45,16 @@ func (r renamerRemoverImpl) Stat(path string) (fs.FileInfo, error) {
return r.StatFn(path)
}
func newRenamerRemoverImpl() renamerRemoverImpl {
return renamerRemoverImpl{
// use fsutil.SafeMove to support cross-device moves
RenameFn: fsutil.SafeMove,
RemoveFn: os.Remove,
RemoveAllFn: os.RemoveAll,
StatFn: os.Stat,
}
}
// Deleter is used to safely delete files and directories from the filesystem.
// During a transaction, files and directories are marked for deletion using
// the Files and Dirs methods. This will rename the files/directories to be
@@ -59,12 +70,7 @@ type Deleter struct {
func NewDeleter() *Deleter {
return &Deleter{
RenamerRemover: renamerRemoverImpl{
RenameFn: os.Rename,
RemoveFn: os.Remove,
RemoveAllFn: os.RemoveAll,
StatFn: os.Stat,
},
RenamerRemover: newRenamerRemoverImpl(),
}
}