mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-06 07:54:22 +00:00
Implement MoveFile functionality in FileManager and corresponding tests
This commit is contained in:
@@ -14,6 +14,7 @@ type FileManager interface {
|
||||
FindFileByName(userID, workspaceID int, filename string) ([]string, error)
|
||||
GetFileContent(userID, workspaceID int, filePath string) ([]byte, error)
|
||||
SaveFile(userID, workspaceID int, filePath string, content []byte) error
|
||||
MoveFile(userID, workspaceID int, srcPath string, dstPath string) error
|
||||
DeleteFile(userID, workspaceID int, filePath string) error
|
||||
GetFileStats(userID, workspaceID int) (*FileCountStats, error)
|
||||
GetTotalFileStats() (*FileCountStats, error)
|
||||
@@ -174,6 +175,34 @@ func (s *Service) SaveFile(userID, workspaceID int, filePath string, content []b
|
||||
return nil
|
||||
}
|
||||
|
||||
// MoveFile moves a file from srcPath to dstPath within the workspace directory.
|
||||
// Both paths must be relative to the workspace directory given by userID and workspaceID.
|
||||
// If the destination file already exists, it will be overwritten.
|
||||
func (s *Service) MoveFile(userID, workspaceID int, srcPath string, dstPath string) error {
|
||||
log := getLogger()
|
||||
|
||||
srcFullPath, err := s.ValidatePath(userID, workspaceID, srcPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dstFullPath, err := s.ValidatePath(userID, workspaceID, dstPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := s.fs.MoveFile(srcFullPath, dstFullPath); err != nil {
|
||||
return fmt.Errorf("failed to move file: %w", err)
|
||||
}
|
||||
|
||||
log.Debug("file moved",
|
||||
"userID", userID,
|
||||
"workspaceID", workspaceID,
|
||||
"src", srcPath,
|
||||
"dst", dstPath)
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteFile deletes the file at the given filePath.
|
||||
// Path must be a relative path within the workspace directory given by userID and workspaceID.
|
||||
func (s *Service) DeleteFile(userID, workspaceID int, filePath string) error {
|
||||
|
||||
Reference in New Issue
Block a user