photoprism/pkg/fs/move.go
Michael Mayer 86dc89c4b9 Config: Show error if originals and storage path seem identical #1642
Signed-off-by: Michael Mayer <michael@photoprism.app>
2024-01-21 14:22:16 +01:00

34 lines
542 B
Go

package fs
import (
"fmt"
"os"
"path/filepath"
)
// Move moves an existing file to a new destination and returns an error if it fails.
func Move(src, dest string) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("move: %s (panic)", r)
}
}()
if err = MkdirAll(filepath.Dir(dest)); err != nil {
return err
}
if err = os.Rename(src, dest); err == nil {
return nil
}
if err = Copy(src, dest); err != nil {
return err
}
if err = os.Remove(src); err != nil {
return err
}
return nil
}