aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2021-05-13 08:58:10 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2021-05-13 08:58:10 -0400
commitb52aa3bf2b9cbb529b861566f6dbed24483c0b67 (patch)
tree817c51f4d321f5ec31bf13ec3650c198dc46ee9a
parent7c4ad319cf21f75b51aae83d025be4cdd07a2a06 (diff)
downloadlevitating-b52aa3bf2b9cbb529b861566f6dbed24483c0b67.tar.gz
levitating-b52aa3bf2b9cbb529b861566f6dbed24483c0b67.zip
Temporary directory is now configurable.
-rw-r--r--captain/config.f907
-rw-r--r--captain/example/levitating.conf2
-rw-r--r--common/utilities.F9046
3 files changed, 51 insertions, 4 deletions
diff --git a/captain/config.f90 b/captain/config.f90
index 2e3ccaa..f3c9bd1 100644
--- a/captain/config.f90
+++ b/captain/config.f90
@@ -65,6 +65,9 @@ implicit none
character(*), parameter::SCRIPT_DIRECTORY_VARIABLE = "script-directory"
character(1024)::script_dir
+ character(*), parameter::TEMP_DIRECTORY_VARIABLE = "temp-directory"
+ character(1024)::temp_dir = "/tmp"
+
contains
subroutine get_variable(str, v)
@@ -104,6 +107,7 @@ contains
end subroutine get_value
subroutine assign_config(cvariable, cvalue)
+ use utilities, only: set_temporary_directory
implicit none
character(*), intent(in)::cvariable, cvalue
@@ -150,6 +154,9 @@ contains
else if(cvariable == LOGLEVEL_VARIABLE) then
read(cvalue, '(I3)') loglevel
+ else if(cvariable == TEMP_DIRECTORY_VARIABLE) then
+ call set_temporary_directory(cvalue)
+
end if
end subroutine assign_config
diff --git a/captain/example/levitating.conf b/captain/example/levitating.conf
index 127c6e6..34dc683 100644
--- a/captain/example/levitating.conf
+++ b/captain/example/levitating.conf
@@ -26,3 +26,5 @@ script-directory = /home/jeff/Workspace/levitating/captain/sql
instructions-directory = /home/jeff/Workspace/levitating/captain/example/instructions
release-directory = /home/jeff/Workspace/levitating/captain/example/releases
+
+temp-directory = /tmp/levitating
diff --git a/common/utilities.F90 b/common/utilities.F90
index e8bceff..4c0c13f 100644
--- a/common/utilities.F90
+++ b/common/utilities.F90
@@ -35,8 +35,32 @@ module utilities
module procedure replace_field_int
end interface
+ character(len=:), pointer::temporary_directory
+
contains
+ subroutine set_temporary_directory(d)
+#ifdef WINDOWS
+ use iso_c_binding, only: c_null_char
+#endif
+ implicit none
+
+ character(*), intent(in)::d
+
+ if(len_trim(d) > 0) then
+
+#ifdef WINDOWS
+ allocate(character(len=(len_trim(d)+1)) :: temporary_directory)
+ temporary_directory = d//c_null_char
+#else
+ allocate(character(len=(len_trim(d))) :: temporary_directory)
+ temporary_directory = d
+#endif
+
+ end if
+
+ end subroutine set_temporary_directory
+
function is_absolute_path(path)
implicit none
@@ -200,12 +224,18 @@ contains
integer::res
tmp_path = c_malloc(int(1024, kind=c_size_t))
- res = GetTempPath(1023, tmp_path)
+ if(.not. associated(temporary_directory)) then
+ res = GetTempPath(1023, tmp_path)
+ else
+ tmp_path = c_loc(temporary_directory)
+ end if
tmp_name = c_malloc(int(1024, kind=c_size_t))
res = GetTempFileName(tmp_path, c_null_ptr, 0, tmp_name)
- call c_free(tmp_path)
+ if(.not.associated(temporary_directory)) then
+ call c_free(tmp_path)
+ end if
! Convert the C Ptr to a Fortran object
clength = c_strlen(tmp_name)
@@ -229,7 +259,15 @@ contains
call random_number(rnum)
write(num_text, *) abs(rnum)
- fullpath = "/tmp/lv."//trim(adjustl(num_text))//".tmp"
+ if(associated(temporary_directory)) then
+ if(temporary_directory(len(temporary_directory):len(temporary_directory)) == "/") then
+ fullpath = temporary_directory//"lv."//trim(adjustl(num_text))//".tmp"
+ else
+ fullpath = temporary_directory//"/lv."//trim(adjustl(num_text))//".tmp"
+ end if
+ else
+ fullpath = "/tmp/lv."//trim(adjustl(num_text))//".tmp"
+ end if
!call write_log("My temp filename is: '"//trim(fullpath)//"'")
#endif
@@ -501,7 +539,7 @@ contains
close(unum)
end if
- call delete_file(tempfilename)
+ call unlink(tempfilename)
deallocate(tempfilename)
end subroutine get_one_line_output_shell_command