Skip to content

Commit 16d3f28

Browse files
committed
non-existent: emit warning, not error
1 parent adcc15c commit 16d3f28

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/stdlib_system.F90

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module stdlib_system
33
c_f_pointer
44
use stdlib_kinds, only: int64, dp, c_bool, c_char
55
use stdlib_strings, only: to_c_char
6-
use stdlib_error, only: state_type, STDLIB_FS_ERROR
6+
use stdlib_error, only: state_type, STDLIB_SUCCESS, STDLIB_FS_ERROR
77
implicit none
88
private
99
public :: sleep
@@ -110,9 +110,10 @@ module stdlib_system
110110
!!
111111
!!### Description
112112
!!
113-
!! This subroutine deletes a specified file. If the file does not exist, or if it is a directory or inaccessible,
114-
!! an error is raised. Errors are handled using the library's `state_type` mechanism. If the optional `err` argument
115-
!! is not provided, exceptions trigger an `error stop`.
113+
!! This subroutine deletes a specified file. If the file is a directory or inaccessible, an error is raised.
114+
!! If the file does not exist, a warning is returned, but no error state. Errors are handled using the
115+
!! library's `state_type` mechanism. If the optional `err` argument is not provided, exceptions trigger
116+
!! an `error stop`.
116117
!!
117118
public :: delete_file
118119

@@ -738,8 +739,8 @@ subroutine delete_file(path, err)
738739
! Check if the path exists
739740
inquire(file=path, exist=file_exists)
740741
if (.not. file_exists) then
741-
! File does not exist, return error status
742-
err0 = state_type(STDLIB_FS_ERROR,'Cannot delete',path,': file does not exist')
742+
! File does not exist, return non-error status
743+
err0 = state_type(STDLIB_SUCCESS,path,' not deleted: file does not exist')
743744
call err0%handle(err)
744745
return
745746
endif

test/system/test_filesystem.f90

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ subroutine test_delete_file_non_existent(error)
7979
! Attempt to delete a file that doesn't exist
8080
call delete_file('non_existent_file.txt', state)
8181

82-
call check(error, state%error(), 'Error should be triggered for non-existent file')
82+
call check(error, state%ok(), 'Error should not be triggered for non-existent file')
8383
if (allocated(error)) return
8484

8585
end subroutine test_delete_file_non_existent

0 commit comments

Comments
 (0)