Changeset 8034 in project


Ignore:
Timestamp:
02/01/08 23:44:09 (12 years ago)
Author:
sjamaan
Message:

Implement 9p:file-create

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/3/9p/trunk/9p-client.scm

    r8033 r8034  
    147147(define (9p:with-handle-to con path procedure)
    148148  (let ((h (9p:path-walk con path)))
    149     (handle-exceptions exn
    150                        (begin
    151                          (9p:file-close h)
    152                          (raise exn)) ;; Just reraise it
    153                        (let ((result (call-with-values (lambda () (procedure h)) list)))
    154                          (9p:file-close h)
    155                          (apply values result)))))
     149    (handle-exceptions
     150     exn
     151     (begin
     152       (9p:file-close h)
     153       (raise exn)) ;; Just reraise it
     154     (let ((result (call-with-values (lambda () (procedure h)) list)))
     155       (9p:file-close h)
     156       (apply values result)))))
    156157
    157158;; Probably want to roll walk and other file ops into one
     
    163164      (9p:handle-iounit-set! h iounit)) ; Otherwise just keep it at the default
    164165    h))
     166
     167;; This duplicates much of with-handle-to, but 9p isn't very consistent here: the
     168;; fid that initially represents the directory is now reused and represents the
     169;; newly created file, so we can't use with-handle-to (or we'd have to reopen the
     170;; file after creating, which is not possible in case of tempfiles)
     171(define (9p:file-create con name perm mode)
     172  (let ((h (9p:path-walk con (pathname-directory name))))
     173    (handle-exceptions
     174     exn
     175     (begin
     176       (9p:file-close h)
     177       (raise exn)) ;; Just reraise it
     178     (let* ((response (9p:request con 'Tcreate (9p:handle-fid h) (pathname-strip-directory name) perm mode))
     179            (iounit (second (9p:message-contents response))))
     180       (unless (zero? iounit)
     181               (9p:handle-iounit-set! h iounit)) ; Otherwise just keep it at the default
     182       h))))
    165183
    166184(define (u8vector-append! . vectors)
     
    222240              (9p:handle-position-set! h (+ pos written))
    223241              (if (not (= written send-size))
    224                   (9p:server-error 'Twrite (sprintf "Unexpected bytecount ~A in Rwrite response (not a proper server error message)" written)))
    225               (printf "WRITTEN: ~S\n" written)
     242                  (9p:server-error 'Twrite (sprintf "Unexpected bytecount ~A instead of ~A in Rwrite response (not a proper server error message)" written send-size)))
    226243              (loop (- bytes-left written) (+ total written))))))))
    227244
Note: See TracChangeset for help on using the changeset viewer.