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

filesystem: error handling, delete_file, is_directory and other #904

Open
wants to merge 29 commits into
base: master
Choose a base branch
from

Conversation

perazz
Copy link
Member

@perazz perazz commented Dec 9, 2024

this PR follows up (without overlapping) on the excellent work ongoing at #874.
Also CC: #14 and j3-fortran/fortran_proposals#100
An initial stdlib_io_filesystem functionality is proposed: because such minimal functionality is intertwined, this PR proposes to introduce the following:

  • extend state_type error handling, that was well accepted for linear algebra, to the whole library (without API changes: just make state_type->linalg_state_type polymorphism)
  • Runtime OS query (saved to static storage for performance)
  • Basic file I/O and sub-processing functions: delete_file, is_directory, run, getfile

stdlib_io_filesystem

  • is_directory(path): logical function
  • call delete_file(path [, err]): optional return state, otherwise exceptions trigger an error stop

stdlib_system

  • call run(cmd [, exit_state] [, command_state] [, stdout] [, stderr]): with optional stdout/stderr outputs loaded onto string_type variables
  • function os_type() returns a cached OS type flag, OS_NAME its name
  • function null_device() returns a cross-platform string path to suppress terminal output

stdlib_io

  • type(string_type) function getfile(fileName [,err] [,delete]) loads a whole ASCII file into a string_type variable all at once, with option to return a state flag, or to request file deletion (delete=.true.) after loading. This function is necessary within this PR for loading screen output.

Comments

  • Usage of external C code has been avoided, but I'm happy to change implementation details if requested. In fpm, there is a policy that the package must be fully compiled as a single-source Fortran file, so C usage is not well integrated, but I don't know what the stdlib policy is in this respect.
  • should delete functionality be unique for either files or directories? otherwise, I will work out a rmdir or delete_dir alternative for them.

cc: @fortran-lang/stdlib @jvdp1 @jalvesz @zoziha @minhqdao

@perazz perazz changed the title filesystem: error handling, delete_file, is_directory filesystem: error handling, delete_file, is_directory and other Dec 9, 2024
@perazz perazz marked this pull request as ready for review December 9, 2024 14:48
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

Successfully merging this pull request may close these issues.

1 participant