91774c4068
Signed-off-by: Michael Mayer <michael@photoprism.app>
34 lines
510 B
Go
34 lines
510 B
Go
package fs
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
// Moves a file to a new destination.
|
|
func Move(src, dest string) (err error) {
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
err = fmt.Errorf("move: %s (panic)", r)
|
|
}
|
|
}()
|
|
|
|
if err := os.MkdirAll(filepath.Dir(dest), ModeDir); 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
|
|
}
|