Bend
Bend copied to clipboard
Add IO functions for moving files and directories
Depends on
- [ ] https://github.com/HigherOrderCO/HVM/issues/421
Add file and moving capabilities to Bend by implementing a move
function that interfaces with the HVM's IO system.
1. move(source, destination, overwrite)
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
: Iftrue
, overwrites the destination if it exists. Otherwise, returns an error if the destination exists. Defaults tofalse
Example Usage
# Moving a file
result = move("old_file.txt", "new_file.txt")
match result:
case Ok(_):
print("File moved successfully")
case Err(e):
print(f"Error moving file: {e}")
# Moving a directory
result = move("old_dir", "new_dir", overwrite=True)
match result:
case Ok(_):
print("Directory moved successfully")
case Err(e):
print(f"Error moving directory: {e}")
Implementation Details
-
Error Handling:
- Implement custom error types in Bend for file operations (e.g.,
FileNotFound
,PermissionDenied
,FileExists
). - Properly map HVM errors to Bend-level errors.
- Implement custom error types in Bend for file operations (e.g.,
-
Type Checking:
- Ensure proper type checking for function arguments.
- Implement appropriate type hints.
-
HVM Integration:
- Use the appropriate HVM calls to perform the move operation.
- Handle the conversion between HVM results and Bend's result type.
-
Documentation:
- Write clear docstrings for the
move
function. - Include usage examples in the documentation.
- Write clear docstrings for the
Integration
- Update Bend's stdlib documentation to include the new
move
function. - If necessary, update any related functions or modules that might interact with file operations.
Considerations
- Consider adding optional parameters for preserving metadata, following symlinks, etc.
- Ensure that the function handles edge cases like moving a file to the same location or moving a file to a read-only destination.
- Implement proper error handling for all possible failure scenarios.
Testing
- Move a file or directory to a new destination.
- Attempt to move a non-existent file or directory.
- Move a file or directory to a destination that already exists
- Move a file or directory to a destination with insufficient permissions.
- Move a file or directory to a read-only destination.