Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IO functions for moving files and directories #688

Open
1 task
kings177 opened this issue Aug 20, 2024 · 0 comments
Open
1 task

Add IO functions for moving files and directories #688

kings177 opened this issue Aug 20, 2024 · 0 comments
Labels
enhancement New feature or request prelude Bend's builtin types and functions

Comments

@kings177
Copy link
Member

kings177 commented Aug 20, 2024

Depends on


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: If true, overwrites the destination if it exists. Otherwise, returns an error if the destination exists. Defaults to false

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

  1. Error Handling:

    • Implement custom error types in Bend for file operations (e.g., FileNotFound, PermissionDenied, FileExists).
    • Properly map HVM errors to Bend-level errors.
  2. Type Checking:

    • Ensure proper type checking for function arguments.
    • Implement appropriate type hints.
  3. HVM Integration:

    • Use the appropriate HVM calls to perform the move operation.
    • Handle the conversion between HVM results and Bend's result type.
  4. Documentation:

    • Write clear docstrings for the move function.
    • Include usage examples in the documentation.

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

  1. Move a file or directory to a new destination.
  2. Attempt to move a non-existent file or directory.
  3. Move a file or directory to a destination that already exists
  4. Move a file or directory to a destination with insufficient permissions.
  5. Move a file or directory to a read-only destination.
@kings177 kings177 added this to the Bend IO lib v0 milestone Aug 20, 2024
@kings177 kings177 changed the title File moving Add IO functions for moving files and directories Aug 26, 2024
@kings177 kings177 added enhancement New feature or request prelude Bend's builtin types and functions labels Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request prelude Bend's builtin types and functions
Projects
None yet
Development

No branches or pull requests

1 participant