Add safety check and state tracking in File's Move method

This commit is contained in:
2026-04-27 23:38:03 +05:00
parent 7ae37d00ae
commit ee41b427e0
+11 -1
View File
@@ -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
}