Implement MoveFile functionality

This commit is contained in:
2025-07-12 11:52:51 +02:00
parent 0b0cd9160e
commit 3ac657486c
3 changed files with 70 additions and 3 deletions

View File

@@ -192,7 +192,7 @@ func (s *Service) MoveFile(userID, workspaceID int, srcPath string, dstPath stri
}
if err := s.fs.MoveFile(srcFullPath, dstFullPath); err != nil {
return fmt.Errorf("failed to move file: %w", err)
return err
}
log.Debug("file moved",

View File

@@ -41,6 +41,12 @@ func (f *osFS) WriteFile(path string, data []byte, perm fs.FileMode) error {
// MoveFile moves the file from src to dst, overwriting if necessary.
func (f *osFS) MoveFile(src, dst string) error {
_, err := os.Stat(src)
if err != nil {
if os.IsNotExist(err) {
return os.ErrNotExist
}
}
if err := os.Rename(src, dst); err != nil {
if os.IsExist(err) {
// If the destination exists, remove it and try again