Skip to content

Commit

Permalink
WIP prevent concurrent make-directory-path
Browse files Browse the repository at this point in the history
  • Loading branch information
owaddell-beckman committed Jun 16, 2024
1 parent a741132 commit 32a9228
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions examples/apt-archive/proxy.ss
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
[#!eof #t]
[,bv (put-bytevector op bv) (lp (fx- remaining (bytevector-length bv)))]))))
(define (fetch! request fop)
(<req> open request [target-file scheme host port method path header])
(<req> open request [scheme host port method path header])
(<result> make
[path path]
[status
Expand All @@ -138,16 +138,15 @@
[200 (copy ip fop (http:get-content-length header))]
[,_ (guard (memv status '(301 302 307 308)))
(json:ref header 'location #f)]))))])]))
(define (add-worker workers path request server)
(define (add-worker workers path target-file request server)
(define tmp-file (path-combine archive (uuid->string (osi_make_uuid))))
(define pid
(spawn
(lambda ()
(define fop (open-binary-file-to-replace tmp-file))
(define result (on-exit (close-port fop) (try (fetch! request fop))))
(match result
[`(<result> [status #t])
(rename-path tmp-file (make-directory-path (<req> target-file request)))]
[`(<result> [status #t]) (rename-path tmp-file target-file)]
[,_ (delete-file tmp-file)])
(send server result))))
(monitor pid)
Expand Down Expand Up @@ -176,9 +175,11 @@
,($state copy*
[requests (ht:set requests path (cons from waiting))]
[workers
(if (null? waiting)
(add-worker workers path msg self)
workers)])))])]))
(cond
[(null? waiting)
(make-directory-path target-file)
(add-worker workers path target-file msg self)]
[else workers])])))])]))
(define (handle-cast msg state) (match msg))
(define (handle-info msg state)
(match msg
Expand Down

0 comments on commit 32a9228

Please sign in to comment.