You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement moving functionality to give Bend the ability to move files and directories. This should support both single file moving and recursive directory moving.
1. move(source, destination, overwrite=False)
@spec move(str, str, bool) -> Result[None,Error]
Moves a file or directory from the source path to the destination path.
Parameters
source: Path of the file or directory to be moved
destination: Path where the file or directory should be moved to
overwrite: If True, overwrites the destination if it exists. If False, returns an error if the destination exists.
Returns Ok(None) if successful, or Err(reason) if an error occurs.
Possible (but not limited to) errors:
FileNotFound: The source file or directory does not exist
PermissionDenied: Lack of permission to read the source or write to the destination
FileExists: The destination already exists and overwrite is False
Examples
# Move a fileresult=move("source.txt", "destination.txt")
# Ok(None)
# Move and overwrite an existing fileresult=move("source.txt", "destination.txt", overwrite=True)
# Ok(None)
# Move a directoryresult=move("source_dir", "dest_dir")
# Ok(None)
# Try to move a non-existent file or directoryresult=move("nonexistent", "dest")
# Err(FileNotFound)
# Try to move to an existing destination without overwriteresult=move("source.txt", "existing.txt")
# Err(FileExists)
Considerations
Handle moving across different filesystems
Consider preserving file metadata (e.g. permissions, timestamps) during moving.
Handle moving directories with large numbers of files efficiently.
Handle symbolic links appropriately (whether to follow them or move the link itself).
Be aware of potential issues with moving files or directories that are currently in use.
Implement proper error handling and propagation.
Test cases to implement
Move a small text file
Move a large binary file
Move an empty directory
Move a directory with multiple files and subdirectories
Attempt to move a non-existent file or directory
Attempt to move to a read-only destination
Move a file or directory to an existing destination with and without overwrite flag
Move a file or directory across different filesystems
Move a file or directory with special characters in the name
Move a symbolic link (both following and not following the link)
Move files and directories with various permission settings
Attempt to move a file or directory into itself or its subdirectory
Move a file or directory that is currently open or in use
The text was updated successfully, but these errors were encountered:
Implement moving functionality to give Bend the ability to move files and directories. This should support both single file moving and recursive directory moving.
1.
move(source, destination, overwrite=False)
Moves a file or directory from the source path to the destination path.
Parameters
source
: Path of the file or directory to be moveddestination
: Path where the file or directory should be moved tooverwrite
: IfTrue
, overwrites the destination if it exists. IfFalse
, returns an error if the destination exists.Returns
Ok(None)
if successful, orErr(reason)
if an error occurs.Possible (but not limited to) errors:
FileNotFound
: The source file or directory does not existPermissionDenied
: Lack of permission to read the source or write to the destinationFileExists
: The destination already exists and overwrite isFalse
Examples
Considerations
Test cases to implement
The text was updated successfully, but these errors were encountered: