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 | |
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')
-rw-r--r-- | player/instructions.f90 | 6 | ||||
-rw-r--r-- | player/player.F90 | 1 | ||||
-rw-r--r-- | player/talking.f90 | 4 | ||||
-rw-r--r-- | player/tasks.f90 | 81 |
4 files changed, 81 insertions, 11 deletions
diff --git a/player/instructions.f90 b/player/instructions.f90 index a3dc97a..1bd25ea 100644 --- a/player/instructions.f90 +++ b/player/instructions.f90 @@ -265,7 +265,11 @@ contains if(.not. all(found,1)) then success = .false. else - success = upload(url, filename) + if(index(filename, "*") > 0 .or. index(filename, "?") > 0) then + success = upload_glob(url, filename) + else + success = upload(url, filename) + end if end if else if(trim(operation) == "download") then diff --git a/player/player.F90 b/player/player.F90 index bac6d6f..d41ec99 100644 --- a/player/player.F90 +++ b/player/player.F90 @@ -106,6 +106,7 @@ contains integer::i identity = " " + token = "None" i = 1 do while(i <= command_argument_count()) diff --git a/player/talking.f90 b/player/talking.f90 index 733f463..5cc3a48 100644 --- a/player/talking.f90 +++ b/player/talking.f90 @@ -23,7 +23,7 @@ contains mod_url = url open(newunit=unit_number, file=filename, status='UNKNOWN', & - access='STREAM', form='FORMATTED', iostat=istatus) + access='STREAM', iostat=istatus) ! form='FORMATTED', if(istatus == 0) then status_code = request_url(mod_url, unit_number, return_type) @@ -69,7 +69,7 @@ contains allocate(character(len=len_trim(url)) :: mod_url) mod_url = url - open(newunit=io, form="formatted", status="scratch", access='stream') + open(newunit=io, status="scratch", access='stream') status_code = request_url(mod_url, io, return_type) close(io) 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) |