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 function for creating new directories #420

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

Add IO function for creating new directories #420

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 a new IO function in the HVM to give Bend the ability to create new directories in the file system.

1. create_directory(path, parents=False, exist_ok=False)

@spec create_directory(str, bool, bool) -> Result[None, Error]

Creates a new directory at the specified path.

Parameters

  • path: The path where the new directory should be created
  • parents: If True, create parent directories as needed. If False, parent directories must exist
  • exist_ok: If True, don't raise an error if the directory already exists

Returns Ok(None) if successful, or Err(reason) if an error occurs.

Possible (but not limited to) errors:

  • FileExists: The directory already exists and exist_ok is False
  • FileNotFound: A parent directory doesn't exist and parents is False
  • PermissionDenied: The user doesn't have permission to create the directory
  • OSError: Other OS-level errors (e.g., disk full, invalid path)

Examples

# Create a new directory
result = create_directory("new_folder")
# Ok(None)
# Create a directory with non-existent parents, creating them as needed
result = create_directory("path/to/new/folder", parents=True)
# Ok(None)
# Create a directory, allowing it to exist
result = create_directory("maybe_existing_folder",  exist_ok=True)
# Ok(None)
# Try to create an existing directory
result = create_directory("existing_folder")
# Err(FileExists)
# Create a directory with non-existent parents
result = create_directory("path/to/new/folder")
# Err(FileNotFound)

Considerations

  • Implement proper error handling and propagation.
  • Ensure thread-safety for directory creation.
  • Handle path normalization (e.g., handling '...' and '.' in paths).
  • Consider preserving or setting specific permissions for newly created directories.
  • Be aware of and handle potential race conditions (e.g., directories being created/deleted concurrently)
  • Implement appropriate logging for debugging.

Test cases to implement

  1. Create a new directory in an existing parent directory
  2. Attempt to create a directory that already exists (with and without exist_ok)
  3. Create a directory with multiple levels of non-existent parent directories (with and without parents flag)
  4. Attempt to create a directory without proper permissions
  5. Create a directory with a very long path name (test path length limits)
  6. Create a directory with special characters in the name
  7. Attempt to create a directory in a read-only file system
  8. Create multiple directories concurrently to test thread-safety
  9. Create a directory where a file with the same name already exists
  10. Attempt to create a directory with an invalid name (e.g., empty string, only whitespace)
  11. Create a directory using relative paths
  12. Create a directory using absolute paths
  13. Test behavior when disk is full
@kings177 kings177 added this to the IO lib v0 milestone Aug 20, 2024
@developedby developedby changed the title Directory creation Add IO function for creating new directories Aug 21, 2024
@imaqtkatt imaqtkatt self-assigned this Aug 22, 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