diff options
author | LKedward <laurence.kedward@bristol.ac.uk> | 2020-10-17 11:56:08 +0100 |
---|---|---|
committer | LKedward <laurence.kedward@bristol.ac.uk> | 2020-10-17 11:56:08 +0100 |
commit | f319d32516be565718a0286f7589d66497daf60f (patch) | |
tree | 5c4805f2ac1457d9c0a9857ebf967a11638b90a7 | |
parent | d3a65e36b28808c2c51ae41fc107f1179e27a08c (diff) | |
download | fpm-f319d32516be565718a0286f7589d66497daf60f.tar.gz fpm-f319d32516be565718a0286f7589d66497daf60f.zip |
Minor fixes: to list_files and mkdir in fpm_filesystem
Fixes to ensure consistency between Windows and Linux: mkdir will not fail if dir already exists; list_files will include hidden files but exclude '.' and '..'
-rw-r--r-- | fpm/src/fpm_filesystem.f90 | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/fpm/src/fpm_filesystem.f90 b/fpm/src/fpm_filesystem.f90 index d2096f1..4c12314 100644 --- a/fpm/src/fpm_filesystem.f90 +++ b/fpm/src/fpm_filesystem.f90 @@ -215,6 +215,8 @@ subroutine mkdir(dir) character(len=*), intent(in) :: dir integer :: stat + if (is_dir(dir)) return + select case (get_os_type()) case (OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD) call execute_command_line('mkdir -p ' // dir, exitstat=stat) @@ -233,6 +235,11 @@ end subroutine mkdir recursive subroutine list_files(dir, files, recurse) + ! Get file & directory names in directory `dir`. + ! + ! - File/directory names return are relative to cwd, ie. preprended with `dir` + ! - Includes files starting with `.` except current directory and parent directory + ! character(len=*), intent(in) :: dir type(string_t), allocatable, intent(out) :: files(:) logical, intent(in), optional :: recurse @@ -242,8 +249,7 @@ recursive subroutine list_files(dir, files, recurse) type(string_t), allocatable :: dir_files(:) type(string_t), allocatable :: sub_dir_files(:) - ! Using `inquire` / exists on directories works with gfortran, but not ifort - if (.not. exists(dir)) then + if (.not. is_dir(dir)) then allocate (files(0)) return end if @@ -252,7 +258,7 @@ recursive subroutine list_files(dir, files, recurse) select case (get_os_type()) case (OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD) - call execute_command_line('ls ' // dir // ' > ' // temp_file, & + call execute_command_line('ls -A ' // dir // ' > ' // temp_file, & exitstat=stat) case (OS_WINDOWS) call execute_command_line('dir /b ' // windows_path(dir) // ' > ' // temp_file, & |