Add safety check and state tracking in File's Move method
This commit is contained in:
+11
-1
@@ -2,6 +2,7 @@ package pkg
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
@@ -47,5 +48,14 @@ func (f *File) Remove() error {
|
||||
}
|
||||
|
||||
func (f *File) Move(path string) error {
|
||||
return os.Rename(f.filepath, path)
|
||||
if f.isMoved {
|
||||
return fmt.Errorf("file already moved")
|
||||
}
|
||||
|
||||
if err := os.Rename(f.filepath, path); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f.isMoved = true
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user