From a42ea711131a36fdb121f3321d2dd5e258b931bf Mon Sep 17 00:00:00 2001 From: Kevin Tew Date: Thu, 20 Jan 2011 14:28:27 -0700 Subject: [PATCH] Scribble with-compile-output fix --- collects/compiler/cm.rkt | 8 +++++++- collects/scribblings/raco/make.scrbl | 10 +++++++++- collects/setup/scribble.rkt | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/collects/compiler/cm.rkt b/collects/compiler/cm.rkt index f014c74771..a80b387476 100644 --- a/collects/compiler/cm.rkt +++ b/collects/compiler/cm.rkt @@ -180,7 +180,13 @@ (set! ok? #t))) (lambda () (if ok? - (rename-file-or-directory tmp-path path #t) + (if (eq? (system-type) 'windows) + (let ([tmp-path2 (make-temporary-file "tmp~a" #f (path-only path))]) + (with-handlers ([exn:fail:filesystem? void]) + (rename-file-or-directory path tmp-path2 #t)) + (rename-file-or-directory tmp-path path #t) + (try-delete-file tmp-path2)) + (rename-file-or-directory tmp-path path #t)) (try-delete-file tmp-path)))))) (define (get-source-sha1 p) diff --git a/collects/scribblings/raco/make.scrbl b/collects/scribblings/raco/make.scrbl index cdcde33c6a..ffdbc02a92 100644 --- a/collects/scribblings/raco/make.scrbl +++ b/collects/scribblings/raco/make.scrbl @@ -311,7 +311,15 @@ returns, @racket[with-compile-output] renames @racket[tmp-path] to exception. Breaks are managed so that the @racket[port] is reliably closed and the @racket[tmp-path] file is reliably deleted if there's a break. The result of @racket[proc] is the result of the -@racket[with-compile-output] call.} +@racket[with-compile-output] call. + +Windows prevents programs from overwriting files that are open. As a result, +@racket[with-compile-output] calls to @racket[rename-file-or-directory] will +fail if the destination file argument is an open file. Windows, however, does +allow you to rename an open file. To avoid overwriting open files +windows, @racket[with-compile-output] creates a second temporary file +@racket[tmp-path2], renames @racket[p] to @racket[tmp-path2], renames +@racket[tmp-path] to @racket[p], and finally deletes @racket[tmp-path2].} @defparam[parallel-lock-client proc ([command (or/c 'lock 'unlock)] [zo-path bytes?] . -> . boolean?)]{ diff --git a/collects/setup/scribble.rkt b/collects/setup/scribble.rkt index 3f59427e25..948b4f4518 100644 --- a/collects/setup/scribble.rkt +++ b/collects/setup/scribble.rkt @@ -643,7 +643,7 @@ (let ([data (list (get-compiled-file-sha1 src-zo) (get-compiled-file-sha1 renderer-path) (get-file-sha1 css-path))]) - (with-output-to-file stamp-file #:exists 'truncate/replace (lambda () (write data))) + (with-compile-output stamp-file (lambda (out tmp-filename) (write data out))) (let ([m (max aux-time src-time)]) (unless (equal? m +inf.0) (file-or-directory-modify-seconds stamp-file m)))))