Skip to content

Commit

Permalink
WIP more robust: curl could leave partial file
Browse files Browse the repository at this point in the history
  • Loading branch information
owaddell-beckman committed Jun 6, 2024
1 parent 22d1dcc commit 2371282
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions examples/apt-archive/proxy.ss
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,19 @@
[status
(match scheme
["https"
(let-values ([(to-stdin from-stdout from-stderr os-pid)
(spawn-os-process "curl"
`("-s" "-o" ,(make-directory-path target-file) ,(format "https://~a~a" host path))
self)])
(define tmp-file (path-combine archive (uuid->string (osi_make_uuid))))
(define-values (to-stdin from-stdout from-stderr os-pid)
(spawn-os-process "curl"
`("-s" "-o" ,tmp-file ,(format "https://~a~a" host path))
self))
(on-exit (delete-file tmp-file)
(receive
[#(process-terminated ,@os-pid ,exit-status ,term-signal)
(and (= exit-status 0) (file-exists? target-file))]))]
(and (= exit-status 0)
(file-exists? tmp-file)
(begin
(rename-path tmp-file (make-directory-path target-file))
#t))]))]
["http"
(let-values ([(ip op) (connect-tcp host port)])
(on-exit (begin (close-port ip) (close-port op))
Expand Down

0 comments on commit 2371282

Please sign in to comment.