mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-06 07:54:22 +00:00
Implement MoveFile functionality
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user