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 #421

Open
Tracked by #416
kings177 opened this issue Aug 20, 2024 · 0 comments
Open
Tracked by #416

Add IO functions for moving files and directories #421

kings177 opened this issue Aug 20, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@kings177
Copy link
Member

kings177 commented Aug 20, 2024

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 file
result = move("source.txt", "destination.txt")
# Ok(None)
# Move and overwrite an existing file
result = move("source.txt", "destination.txt", overwrite=True)
# Ok(None)
# Move a directory
result = move("source_dir", "dest_dir")
# Ok(None)
# Try to move a non-existent file or directory
result = move("nonexistent", "dest")
# Err(FileNotFound)
# Try to move to an existing destination without overwrite
result = 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

  1. Move a small text file
  2. Move a large binary file
  3. Move an empty directory
  4. Move a directory with multiple files and subdirectories
  5. Attempt to move a non-existent file or directory
  6. Attempt to move to a read-only destination
  7. Move a file or directory to an existing destination with and without overwrite flag
  8. Move a file or directory across different filesystems
  9. Move a file or directory with special characters in the name
  10. Move a symbolic link (both following and not following the link)
  11. Move files and directories with various permission settings
  12. Attempt to move a file or directory into itself or its subdirectory
  13. Move a file or directory that is currently open or in use
@kings177 kings177 added this to the IO lib v0 milestone Aug 20, 2024
@developedby developedby changed the title File moving Add IO functions for moving files and directories Aug 21, 2024
@kings177 kings177 added the enhancement New feature or request label Aug 29, 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
Projects
None yet
Development

No branches or pull requests

2 participants