diff options
author | Jeffrey Armstrong <jeff@approximatrix.com> | 2021-04-14 10:54:27 -0400 |
---|---|---|
committer | Jeffrey Armstrong <jeff@approximatrix.com> | 2021-04-14 10:54:27 -0400 |
commit | 05b91a7ca0aace044621d8db1e82f4772181d893 (patch) | |
tree | 44bf7c8c284c3363f353553c12046e5ca4de40b7 /player/tasks.f90 | |
parent | 14441b7f0d6dd0a101b38a4500fe1f662ae00215 (diff) | |
download | levitating-05b91a7ca0aace044621d8db1e82f4772181d893.tar.gz levitating-05b91a7ca0aace044621d8db1e82f4772181d893.zip |
Fixed binary transfers to maintain file integrity. Added globbed file upload capabilities. Fixed memory overrun issues due to problems parsing ls output.
Diffstat (limited to 'player/tasks.f90')
-rw-r--r-- | player/tasks.f90 | 81 |
1 files changed, 73 insertions, 8 deletions
diff --git a/player/tasks.f90 b/player/tasks.f90 index 87b7d66..2487e73 100644 --- a/player/tasks.f90 +++ b/player/tasks.f90 @@ -69,30 +69,84 @@ contains end function shell - function upload(url, source_filename) + function upload_glob(url, mask) result(res) + use utilities + implicit none + + logical::res + character(*), intent(in)::url + character(*), intent(in)::mask + + character(DIR_LIST_STRING_LENGTH), dimension(:), pointer::files + logical, dimension(:), allocatable::statuses + integer::i + + ! We can cheat by using the get_files_in_directory function since it + ! is merely calling ls/dir, which will resolve the glob + files => get_files_in_directory(mask) + + !allocate(files(2)) + !files(1) = "/tmp/example/jagcdenc2.zip" + !files(2) = "/tmp/example/jagenc2.zip" + + if(associated(files)) then + + allocate(statuses(size(files))) + do i = 1, size(files) + statuses(i) = upload(url, files(i)) + end do + + res = all(statuses) + + deallocate(statuses) + deallocate(files) + + else + + res = .false. + + end if + + end function upload_glob + + recursive function upload(url, source_filename) result(res) use config, only: token, captain use gemini_protocol, only: titan_post_url, STATUS_SUCCESS implicit none - logical::upload + logical::res character(*), intent(in)::url character(*), intent(in)::source_filename character(len=:), allocatable::mod_url integer(kind=8)::file_size - integer::unit_number, istatus, url_length + integer::unit_number, istatus, url_length, i + + ! Check for globbing - sloppy, but still... + if(index(source_filename, "*") > 0 .or. index(source_filename, "?") > 0) then + res = upload_glob(url, source_filename) + return + + end if + + ! If we're here, we have a single filename to upload inquire(file=source_filename, size=file_size) open(newunit=unit_number, file=trim(source_filename), status='UNKNOWN', & access='STREAM', form='UNFORMATTED', iostat=istatus) if(index(url, "://") > 0) then - allocate(character(len=len_trim(url)) :: mod_url) + ! Leave room for a possble filename + url_length = len_trim(url) + len_trim(source_filename) + + allocate(character(len=url_length) :: mod_url) mod_url = url else - url_length = len_trim(url) + len_trim(captain) + 16 + ! Leave room for a possble filename + url_length = len_trim(url) + len_trim(source_filename) + len_trim(captain) + 16 + allocate(character(len=url_length) :: mod_url) mod_url = "titan://"//trim(captain) if(url(1:1) == "/") then @@ -102,12 +156,23 @@ contains end if end if + ! If the URL ends in a slash, it's a folder, add the filename base. + if(mod_url(len_trim(mod_url):len_trim(mod_url)) == "/") then + i = max(index(source_filename, "/", back=.true.), index(source_filename, "\", back=.true.)) + if(i > 0) then + mod_url = trim(mod_url)//source_filename(i+1:len_trim(source_filename)) + else + mod_url = trim(mod_url)//trim(source_filename) + end if + end if + if(istatus == 0) then + Print *, "Writing "//trim(mod_url) istatus = titan_post_url(mod_url, unit_number, file_size, token) - upload = (istatus == STATUS_SUCCESS) + res = (istatus == STATUS_SUCCESS) close(unit_number) else - upload = .false. + res = .false. end if deallocate(mod_url) @@ -145,7 +210,7 @@ contains end if open(newunit=unit_number, file=trim(destination_filename), status='UNKNOWN', & - access='STREAM', form='FORMATTED', iostat=istatus) + access='STREAM', iostat=istatus) ! , form='FORMATTED', if(istatus == 0) then istatus = request_url(mod_url, unit_number, mimetype) |