From 5256fc0d58f9a359f074ef524292feaad5a741fd Mon Sep 17 00:00:00 2001 From: Federico Perini Date: Mon, 3 Mar 2025 08:29:53 +0100 Subject: [PATCH 01/11] add specs --- doc/specs/stdlib_io.md | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/doc/specs/stdlib_io.md b/doc/specs/stdlib_io.md index 0ae2b11b3..1b96e0834 100644 --- a/doc/specs/stdlib_io.md +++ b/doc/specs/stdlib_io.md @@ -301,3 +301,58 @@ Exceptions trigger an `error stop` unless the optional `err` argument is provide ```fortran {!example/io/example_get_file.f90!} ``` + +## `delete_file` - Delete a file + +### Status + +Experimental + +### Description + +This subroutine deletes a specified file from the filesystem. It ensures that the file exists and is not a directory before attempting deletion. +If the file cannot be deleted due to permissions, being a directory, or other issues, an error is raised. +The function provides an optional error-handling mechanism via the `state_type` class. If the `err` argument is not provided, exceptions will trigger an `error stop`. + +### Syntax + +`call [[stdlib_fs(module):delete_file(subroutine)]] (path [, err])` + +### Class +Subroutine + +### Arguments + +`path`: Shall be a character string containing the path to the file to be deleted. It is an `intent(in)` argument. + +`err` (optional): Shall be a `type(state_type)` variable for error handling. If provided, errors are returned as a state object. If not provided, the program stops execution on error. + +### Behavior + +- Checks if the file exists. If not, an error is raised. +- Ensures the path is not a directory before deletion. +- Attempts to delete the file, raising an error if unsuccessful. + +### Return values + +The file is removed from the filesystem if the operation is successful. If the operation fails, an error is raised. + +### Example + +```fortran +program example_delete_file + use stdlib_fs + implicit none + + type(state_type) :: err + + ! Delete a file with error handling + call delete_file("example.txt", err) + + if (err%error()) then + print *, "Failed to delete file:", err%print() + else + print *, "File deleted successfully." + end if +end program example_delete_file +``` From b627637687b0969aa683d766ade23d7dc865bdd5 Mon Sep 17 00:00:00 2001 From: Federico Perini Date: Wed, 26 Mar 2025 08:30:23 +0100 Subject: [PATCH 02/11] add implementation --- src/stdlib_system.F90 | 61 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/src/stdlib_system.F90 b/src/stdlib_system.F90 index 5dade255a..03bcebaa6 100644 --- a/src/stdlib_system.F90 +++ b/src/stdlib_system.F90 @@ -98,7 +98,23 @@ module stdlib_system !! Windows, and various UNIX-like environments. On unsupported operating systems, the function will return `.false.`. !! public :: is_directory - + +!! version: experimental +!! +!! Deletes a specified file from the filesystem. +!! ([Specification](../page/specs/stdlib_system.html#delete_file-delete-a-file)) +!! +!!### Summary +!! Subroutine to safely delete a file from the filesystem. It handles errors gracefully using the library's `state_type`. +!! +!!### Description +!! +!! This subroutine deletes a specified file. If the file does not exist, or if it is a directory or inaccessible, +!! an error is raised. Errors are handled using the library's `state_type` mechanism. If the optional `err` argument +!! is not provided, exceptions trigger an `error stop`. +!! +public :: delete_file + !! version: experimental !! !! Returns the file path of the null device, which discards all data written to it. @@ -707,4 +723,47 @@ end function process_null_device end function null_device +!> Delete a file at the given path. +subroutine delete_file(path, err) + character(*), intent(in) :: path + type(state_type), optional, intent(out) :: err + + !> Local variables + integer :: file_unit, ios + type(state_type) :: err0 + character(len=512) :: msg + logical :: file_exists + + ! Check if the path exists + inquire(file=path, exist=file_exists) + if (.not. file_exists) then + ! File does not exist, return error status + err0 = state_type(STDLIB_FS_ERROR,'Cannot delete',path,': file does not exist') + call err0%handle(err) + return + endif + + ! Verify the file is not a directory + if (is_directory(path)) then + ! If unable to open, assume it's a directory or inaccessible + err0 = state_type(STDLIB_FS_ERROR,'Cannot delete',path,'- is a directory') + call err0%handle(err) + return + end if + + ! Close and delete the file + open(newunit=file_unit, file=path, status='old', iostat=ios, iomsg=msg) + if (ios /= 0) then + err0 = state_type(STDLIB_FS_ERROR,'Cannot delete',path,'-',msg) + call err0%handle(err) + return + end if + close(unit=file_unit, status='delete', iostat=ios, iomsg=msg) + if (ios /= 0) then + err0 = state_type(STDLIB_FS_ERROR,'Cannot delete',path,'-',msg) + call err0%handle(err) + return + end if +end subroutine delete_file + end module stdlib_system From ca8f52aead94d776896ec091646035d2b45587a7 Mon Sep 17 00:00:00 2001 From: Federico Perini Date: Wed, 26 Mar 2025 08:30:41 +0100 Subject: [PATCH 03/11] fix `is_directory` doc path --- src/stdlib_system.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stdlib_system.F90 b/src/stdlib_system.F90 index 03bcebaa6..9c1bd1329 100644 --- a/src/stdlib_system.F90 +++ b/src/stdlib_system.F90 @@ -86,7 +86,7 @@ module stdlib_system !! version: experimental !! !! Tests if a given path matches an existing directory. -!! ([Specification](../page/specs/stdlib_io.html#is_directory-test-if-a-path-is-a-directory)) +!! ([Specification](../page/specs/stdlib_system.html#is_directory-test-if-a-path-is-a-directory)) !! !!### Summary !! Function to evaluate whether a specified path corresponds to an existing directory. From 6265c8e9227caebda539b9f826406f1bb7f509f4 Mon Sep 17 00:00:00 2001 From: Federico Perini Date: Wed, 26 Mar 2025 08:33:17 +0100 Subject: [PATCH 04/11] add `use`s --- src/stdlib_system.F90 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/stdlib_system.F90 b/src/stdlib_system.F90 index 9c1bd1329..adb743858 100644 --- a/src/stdlib_system.F90 +++ b/src/stdlib_system.F90 @@ -3,6 +3,7 @@ module stdlib_system c_f_pointer use stdlib_kinds, only: int64, dp, c_bool, c_char use stdlib_strings, only: to_c_char +use stdlib_error, only: state_type, STDLIB_FS_ERROR implicit none private public :: sleep From 9ddf034e2522cdfd2b9ff6df53757333115fb5b1 Mon Sep 17 00:00:00 2001 From: Federico Perini Date: Wed, 26 Mar 2025 08:35:47 +0100 Subject: [PATCH 05/11] add tests --- test/system/test_filesystem.f90 | 86 ++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 2 deletions(-) diff --git a/test/system/test_filesystem.f90 b/test/system/test_filesystem.f90 index 843763af9..d4bc08f30 100644 --- a/test/system/test_filesystem.f90 +++ b/test/system/test_filesystem.f90 @@ -1,6 +1,7 @@ module test_filesystem use testdrive, only : new_unittest, unittest_type, error_type, check, skip_test - use stdlib_system, only: is_directory + use stdlib_system, only: is_directory, delete_file + use stdlib_error, only: state_type implicit none @@ -13,7 +14,10 @@ subroutine collect_suite(testsuite) testsuite = [ & new_unittest("fs_is_directory_dir", test_is_directory_dir), & - new_unittest("fs_is_directory_file", test_is_directory_file) & + new_unittest("fs_is_directory_file", test_is_directory_file), & + new_unittest("fs_delete_non_existent", test_delete_file_non_existent), & + new_unittest("fs_delete_existing_file", test_delete_file_existing), & + new_unittest("fs_delete_file_being_dir", test_delete_directory) & ] end subroutine collect_suite @@ -67,6 +71,84 @@ subroutine test_is_directory_file(error) end subroutine test_is_directory_file + subroutine test_delete_file_non_existent(error) + !> Error handling + type(error_type), allocatable, intent(out) :: error + type(state_type) :: state + + ! Attempt to delete a file that doesn't exist + call delete_file('non_existent_file.txt', state) + + call check(error, state%error(), 'Error should be triggered for non-existent file') + if (allocated(error)) return + + end subroutine test_delete_file_non_existent + + subroutine test_delete_file_existing(error) + !> Error handling + type(error_type), allocatable, intent(out) :: error + + character(len=256) :: filename + type(state_type) :: state + integer :: ios,iunit + logical :: is_present + character(len=512) :: msg + + filename = 'existing_file.txt' + + ! Create a file to be deleted + open(newunit=iunit, file=filename, status='replace', iostat=ios, iomsg=msg) + call check(error, ios==0, 'Failed to create test file') + if (allocated(error)) return + close(iunit) + + ! Attempt to delete the existing file + call delete_file(filename, state) + + ! Check deletion successful + call check(error, state%ok(), 'delete_file returned '//state%print()) + if (allocated(error)) return + + ! Check if the file was successfully deleted (should no longer exist) + inquire(file=filename, exist=is_present) + + call check(error, .not.is_present, 'File still present after delete') + if (allocated(error)) return + + end subroutine test_delete_file_existing + + subroutine test_delete_directory(error) + !> Error handling + type(error_type), allocatable, intent(out) :: error + character(len=256) :: filename + type(state_type) :: state + integer :: ios,iocmd + character(len=512) :: msg + + filename = 'test_directory' + + ! The directory is not nested: it should be cross-platform to just call `mkdir` + print *, 'mkdir' + call execute_command_line('mkdir ' // filename, exitstat=ios, cmdstat=iocmd, cmdmsg=msg) + call check(error, ios==0 .and. iocmd==0, 'Cannot init delete_directory test: '//trim(msg)) + if (allocated(error)) return + + ! Attempt to delete a directory (which should fail) + print *, 'dfelete' + call delete_file(filename, state) + + ! Check that an error was raised since the target is a directory + call check(error, state%error(), 'Error was not triggered trying to delete directory') + if (allocated(error)) return + + ! Clean up: remove the empty directory + print *, 'rmdir' + call execute_command_line('rmdir ' // filename, exitstat=ios, cmdstat=iocmd, cmdmsg=msg) + call check(error, ios==0 .and. iocmd==0, 'Cannot cleanup delete_directory test: '//trim(msg)) + if (allocated(error)) return + + end subroutine test_delete_directory + end module test_filesystem From be1274b5e4829258fa1d2af5c350766146826cde Mon Sep 17 00:00:00 2001 From: Federico Perini Date: Wed, 26 Mar 2025 08:38:48 +0100 Subject: [PATCH 06/11] cleanup --- test/system/test_filesystem.f90 | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/system/test_filesystem.f90 b/test/system/test_filesystem.f90 index d4bc08f30..88647ed45 100644 --- a/test/system/test_filesystem.f90 +++ b/test/system/test_filesystem.f90 @@ -128,13 +128,11 @@ subroutine test_delete_directory(error) filename = 'test_directory' ! The directory is not nested: it should be cross-platform to just call `mkdir` - print *, 'mkdir' call execute_command_line('mkdir ' // filename, exitstat=ios, cmdstat=iocmd, cmdmsg=msg) call check(error, ios==0 .and. iocmd==0, 'Cannot init delete_directory test: '//trim(msg)) if (allocated(error)) return ! Attempt to delete a directory (which should fail) - print *, 'dfelete' call delete_file(filename, state) ! Check that an error was raised since the target is a directory @@ -142,7 +140,6 @@ subroutine test_delete_directory(error) if (allocated(error)) return ! Clean up: remove the empty directory - print *, 'rmdir' call execute_command_line('rmdir ' // filename, exitstat=ios, cmdstat=iocmd, cmdmsg=msg) call check(error, ios==0 .and. iocmd==0, 'Cannot cleanup delete_directory test: '//trim(msg)) if (allocated(error)) return From 7346b8e6804d77959b0b27a6fb9f11e793904fcc Mon Sep 17 00:00:00 2001 From: Federico Perini Date: Wed, 26 Mar 2025 08:53:44 +0100 Subject: [PATCH 07/11] move doc to `stdlib_system` --- doc/specs/stdlib_io.md | 54 -------------------------------------- doc/specs/stdlib_system.md | 54 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/doc/specs/stdlib_io.md b/doc/specs/stdlib_io.md index 1b96e0834..9986223b6 100644 --- a/doc/specs/stdlib_io.md +++ b/doc/specs/stdlib_io.md @@ -302,57 +302,3 @@ Exceptions trigger an `error stop` unless the optional `err` argument is provide {!example/io/example_get_file.f90!} ``` -## `delete_file` - Delete a file - -### Status - -Experimental - -### Description - -This subroutine deletes a specified file from the filesystem. It ensures that the file exists and is not a directory before attempting deletion. -If the file cannot be deleted due to permissions, being a directory, or other issues, an error is raised. -The function provides an optional error-handling mechanism via the `state_type` class. If the `err` argument is not provided, exceptions will trigger an `error stop`. - -### Syntax - -`call [[stdlib_fs(module):delete_file(subroutine)]] (path [, err])` - -### Class -Subroutine - -### Arguments - -`path`: Shall be a character string containing the path to the file to be deleted. It is an `intent(in)` argument. - -`err` (optional): Shall be a `type(state_type)` variable for error handling. If provided, errors are returned as a state object. If not provided, the program stops execution on error. - -### Behavior - -- Checks if the file exists. If not, an error is raised. -- Ensures the path is not a directory before deletion. -- Attempts to delete the file, raising an error if unsuccessful. - -### Return values - -The file is removed from the filesystem if the operation is successful. If the operation fails, an error is raised. - -### Example - -```fortran -program example_delete_file - use stdlib_fs - implicit none - - type(state_type) :: err - - ! Delete a file with error handling - call delete_file("example.txt", err) - - if (err%error()) then - print *, "Failed to delete file:", err%print() - else - print *, "File deleted successfully." - end if -end program example_delete_file -``` diff --git a/doc/specs/stdlib_system.md b/doc/specs/stdlib_system.md index 22b705f1c..eb9b61347 100644 --- a/doc/specs/stdlib_system.md +++ b/doc/specs/stdlib_system.md @@ -492,3 +492,57 @@ None. {!example/system/example_null_device.f90!} ``` +## `delete_file` - Delete a file + +### Status + +Experimental + +### Description + +This subroutine deletes a specified file from the filesystem. It ensures that the file exists and is not a directory before attempting deletion. +If the file cannot be deleted due to permissions, being a directory, or other issues, an error is raised. +The function provides an optional error-handling mechanism via the `state_type` class. If the `err` argument is not provided, exceptions will trigger an `error stop`. + +### Syntax + +`call [[stdlib_fs(module):delete_file(subroutine)]] (path [, err])` + +### Class +Subroutine + +### Arguments + +`path`: Shall be a character string containing the path to the file to be deleted. It is an `intent(in)` argument. + +`err` (optional): Shall be a `type(state_type)` variable for error handling. If provided, errors are returned as a state object. If not provided, the program stops execution on error. + +### Behavior + +- Checks if the file exists. If not, an error is raised. +- Ensures the path is not a directory before deletion. +- Attempts to delete the file, raising an error if unsuccessful. + +### Return values + +The file is removed from the filesystem if the operation is successful. If the operation fails, an error is raised. + +### Example + +```fortran +program example_delete_file + use stdlib_fs + implicit none + + type(state_type) :: err + + ! Delete a file with error handling + call delete_file("example.txt", err) + + if (err%error()) then + print *, "Failed to delete file:", err%print() + else + print *, "File deleted successfully." + end if +end program example_delete_file +``` From f7ef8f6ebe5e8c8c09776ae18e0ef47e249a7b66 Mon Sep 17 00:00:00 2001 From: Federico Perini Date: Wed, 26 Mar 2025 08:55:55 +0100 Subject: [PATCH 08/11] add example --- doc/specs/stdlib_system.md | 16 +--------------- example/system/CMakeLists.txt | 1 + example/system/example_delete_file.f90 | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 example/system/example_delete_file.f90 diff --git a/doc/specs/stdlib_system.md b/doc/specs/stdlib_system.md index eb9b61347..ba34cfa0d 100644 --- a/doc/specs/stdlib_system.md +++ b/doc/specs/stdlib_system.md @@ -530,19 +530,5 @@ The file is removed from the filesystem if the operation is successful. If the o ### Example ```fortran -program example_delete_file - use stdlib_fs - implicit none - - type(state_type) :: err - - ! Delete a file with error handling - call delete_file("example.txt", err) - - if (err%error()) then - print *, "Failed to delete file:", err%print() - else - print *, "File deleted successfully." - end if -end program example_delete_file +{!example/system/example_delete_file.f90!} ``` diff --git a/example/system/CMakeLists.txt b/example/system/CMakeLists.txt index 28474ea4d..a2a7525c9 100644 --- a/example/system/CMakeLists.txt +++ b/example/system/CMakeLists.txt @@ -1,4 +1,5 @@ ADD_EXAMPLE(get_runtime_os) +ADD_EXAMPLE(delete_file) ADD_EXAMPLE(is_directory) ADD_EXAMPLE(null_device) ADD_EXAMPLE(os_type) diff --git a/example/system/example_delete_file.f90 b/example/system/example_delete_file.f90 new file mode 100644 index 000000000..9494044c1 --- /dev/null +++ b/example/system/example_delete_file.f90 @@ -0,0 +1,18 @@ +! Demonstrate usage of `delete_file` +program example_delete_file + use stdlib_system, only: delete_file + use stdlib_error, only: state_type + implicit none + + type(state_type) :: err + character(*), parameter :: filename = "example.txt" + + ! Delete a file with error handling + call delete_file(filename, err) + + if (err%error()) then + print *, err%print() + else + print *, "File "//filename//" deleted successfully." + end if +end program example_delete_file From adcc15cc24e9c1425b4c8d97026b110d6577ec67 Mon Sep 17 00:00:00 2001 From: Federico Perini Date: Wed, 26 Mar 2025 09:08:59 +0100 Subject: [PATCH 09/11] fix some module references in the docs --- doc/specs/stdlib_system.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/doc/specs/stdlib_system.md b/doc/specs/stdlib_system.md index ba34cfa0d..96eebb2e8 100644 --- a/doc/specs/stdlib_system.md +++ b/doc/specs/stdlib_system.md @@ -24,7 +24,7 @@ Additionally, a callback function can be specified to execute upon process compl ### Syntax -`process = ` [[stdlib_subprocess(module):run(interface)]] `(args [, stdin] [, want_stdout] [, want_stderr] [, callback] [, payload])` +`process = ` [[stdlib_system(module):run(interface)]] `(args [, stdin] [, want_stdout] [, want_stderr] [, callback] [, payload])` ### Arguments @@ -69,7 +69,7 @@ Additionally, a callback function can be specified to execute upon process compl ### Syntax -`process = ` [[stdlib_subprocess(module):runasync(interface)]] `(args [, stdin] [, want_stdout] [, want_stderr] [, callback] [, payload])` +`process = ` [[stdlib_system(module):runasync(interface)]] `(args [, stdin] [, want_stdout] [, want_stderr] [, callback] [, payload])` ### Arguments @@ -108,7 +108,7 @@ This is useful for monitoring the status of asynchronous processes created with ### Syntax -`status = ` [[stdlib_subprocess(module):is_running(interface)]] `(process)` +`status = ` [[stdlib_system(module):is_running(interface)]] `(process)` ### Arguments @@ -139,7 +139,7 @@ This is useful for determining whether asynchronous processes created with the ` ### Syntax -`status = ` [[stdlib_subprocess(module):is_completed(interface)]] `(process)` +`status = ` [[stdlib_system(module):is_completed(interface)]] `(process)` ### Arguments @@ -174,7 +174,7 @@ The result is a real value representing the elapsed time in seconds, measured fr ### Syntax -`delta_t = ` [[stdlib_subprocess(module):elapsed(subroutine)]] `(process)` +`delta_t = ` [[stdlib_system(module):elapsed(subroutine)]] `(process)` ### Arguments @@ -212,7 +212,7 @@ in case of process hang or delay. ### Syntax -`call ` [[stdlib_subprocess(module):wait(subroutine)]] `(process [, max_wait_time])` +`call ` [[stdlib_system(module):wait(subroutine)]] `(process [, max_wait_time])` ### Arguments @@ -243,7 +243,7 @@ This is especially useful for monitoring asynchronous processes and retrieving t ### Syntax -`call ` [[stdlib_subprocess(module):update(subroutine)]] `(process)` +`call ` [[stdlib_system(module):update(subroutine)]] `(process)` ### Arguments @@ -269,7 +269,7 @@ This interface is useful when a process needs to be forcefully stopped, for exam ### Syntax -`call ` [[stdlib_subprocess(module):kill(subroutine)]] `(process, success)` +`call ` [[stdlib_system(module):kill(subroutine)]] `(process, success)` ### Arguments @@ -431,7 +431,7 @@ It is designed to work across multiple platforms. On Windows, paths with both fo ### Syntax -`result = [[stdlib_io(module):is_directory(function)]] (path)` +`result = [[stdlib_system(module):is_directory(function)]] (path)` ### Class @@ -506,7 +506,7 @@ The function provides an optional error-handling mechanism via the `state_type` ### Syntax -`call [[stdlib_fs(module):delete_file(subroutine)]] (path [, err])` +`call [[stdlib_system(module):delete_file(subroutine)]] (path [, err])` ### Class Subroutine From 16d3f28278e61aa7aa8d401ddf0f7512025508cf Mon Sep 17 00:00:00 2001 From: Federico Perini Date: Mon, 31 Mar 2025 08:44:36 +0200 Subject: [PATCH 10/11] non-existent: emit warning, not error --- src/stdlib_system.F90 | 13 +++++++------ test/system/test_filesystem.f90 | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/stdlib_system.F90 b/src/stdlib_system.F90 index adb743858..96b507d56 100644 --- a/src/stdlib_system.F90 +++ b/src/stdlib_system.F90 @@ -3,7 +3,7 @@ module stdlib_system c_f_pointer use stdlib_kinds, only: int64, dp, c_bool, c_char use stdlib_strings, only: to_c_char -use stdlib_error, only: state_type, STDLIB_FS_ERROR +use stdlib_error, only: state_type, STDLIB_SUCCESS, STDLIB_FS_ERROR implicit none private public :: sleep @@ -110,9 +110,10 @@ module stdlib_system !! !!### Description !! -!! This subroutine deletes a specified file. If the file does not exist, or if it is a directory or inaccessible, -!! an error is raised. Errors are handled using the library's `state_type` mechanism. If the optional `err` argument -!! is not provided, exceptions trigger an `error stop`. +!! This subroutine deletes a specified file. If the file is a directory or inaccessible, an error is raised. +!! If the file does not exist, a warning is returned, but no error state. Errors are handled using the +!! library's `state_type` mechanism. If the optional `err` argument is not provided, exceptions trigger +!! an `error stop`. !! public :: delete_file @@ -738,8 +739,8 @@ subroutine delete_file(path, err) ! Check if the path exists inquire(file=path, exist=file_exists) if (.not. file_exists) then - ! File does not exist, return error status - err0 = state_type(STDLIB_FS_ERROR,'Cannot delete',path,': file does not exist') + ! File does not exist, return non-error status + err0 = state_type(STDLIB_SUCCESS,path,' not deleted: file does not exist') call err0%handle(err) return endif diff --git a/test/system/test_filesystem.f90 b/test/system/test_filesystem.f90 index 88647ed45..4cf1690e4 100644 --- a/test/system/test_filesystem.f90 +++ b/test/system/test_filesystem.f90 @@ -79,7 +79,7 @@ subroutine test_delete_file_non_existent(error) ! Attempt to delete a file that doesn't exist call delete_file('non_existent_file.txt', state) - call check(error, state%error(), 'Error should be triggered for non-existent file') + call check(error, state%ok(), 'Error should not be triggered for non-existent file') if (allocated(error)) return end subroutine test_delete_file_non_existent From 53ffe5a4149a96158c9a8170a46664e63407f47e Mon Sep 17 00:00:00 2001 From: Federico Perini Date: Mon, 31 Mar 2025 09:06:26 +0200 Subject: [PATCH 11/11] intel directory fix --- src/stdlib_system.F90 | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/stdlib_system.F90 b/src/stdlib_system.F90 index 96b507d56..a9c3e4d55 100644 --- a/src/stdlib_system.F90 +++ b/src/stdlib_system.F90 @@ -736,7 +736,17 @@ subroutine delete_file(path, err) character(len=512) :: msg logical :: file_exists + ! Verify the file is not a directory. + if (is_directory(path)) then + ! If unable to open, assume it's a directory or inaccessible + err0 = state_type(STDLIB_FS_ERROR,'Cannot delete',path,'- is a directory') + call err0%handle(err) + return + end if + ! Check if the path exists + ! Because Intel compilers return .false. if path is a directory, this must be tested + ! _after_ the directory test inquire(file=path, exist=file_exists) if (.not. file_exists) then ! File does not exist, return non-error status @@ -745,14 +755,6 @@ subroutine delete_file(path, err) return endif - ! Verify the file is not a directory - if (is_directory(path)) then - ! If unable to open, assume it's a directory or inaccessible - err0 = state_type(STDLIB_FS_ERROR,'Cannot delete',path,'- is a directory') - call err0%handle(err) - return - end if - ! Close and delete the file open(newunit=file_unit, file=path, status='old', iostat=ios, iomsg=msg) if (ios /= 0) then