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 removing files and directories #685

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

Add IO functions for removing files and directories #685

kings177 opened this issue Aug 20, 2024 · 0 comments

Comments

@kings177
Copy link
Member

kings177 commented Aug 20, 2024

Depends on


Add file and directory removal capabilities to Bend by implementing remove and remove_all functions that interface with the HVM's IO system.

1. remove(path)

Removes a file or an empty directory at the specified path.

Parameters

  • path: Path of the file or empty directory to be removed

Example Usage

# Remove a file
result = remove("text.txt")
match result:
    case Ok(_):
        print("File removed successfully")
    case Err(e):
        print(f"Error removing file: {e}")
# Remove an empty directory
result = remove("empty_dir")
match result:
    case Ok(_):
        print("Directory removed successfully")
    case Err(e):
        print(f"Error removing directory: {e}")

2. remove_all(path)

Removes a directory at path, along with all of its contents.

Parameters

  • path: Path of the directory to be removed

Example Usage

# Remove a directory and all its contents
result = remove_all("non_empty_dir")
match result:
    case Ok(_):
        print("Directory and its contents removed successfully")
    case Err(e):
        print(f"Error removing directory: {e}")

Implementation Details

  • remove_all should handle recursive deletion of subdirectories and files.
  • Both functions should properly handle and report errors from the HVM layer (e.g., FileNotFound, PermissionDenied, NotEmpty, NotADirectory, OSError).
  • Write clear docstrings for the remove and remove_all functions, explaining their purpose and usage.

Considerations

  • Consider the behavior when removing symbolic links.
  • Implement proper error handling for invalid paths, permissions, and other potential issues.

Testing

  1. Remove a file.
  2. Remove an empty directory.
  3. Remove a directory containing files and subdirectories with remove_all.
  4. Remove a symbolic link.
  5. Attempt to remove a non-empty directory with remove.
  6. Attempt to remove a file or directory without sufficient permissions.
  7. Attempt to remove a non-existent file or directory.
  8. Attempt to remove a file or directory with an invalid path.
@kings177 kings177 added this to the Bend IO lib v0 milestone Aug 20, 2024
@kings177 kings177 changed the title File deletion Add IO functions for removing files and directories Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant