add `make-parent-directory`

pull/84/head
Matthew Butterick 9 years ago
parent c6f9015922
commit e12c40e29e

@ -18,8 +18,8 @@
(define (paths->key source-path [template-path #f]) (define (paths->key source-path [template-path #f])
;; key is list of file + mod-time pairs ;; key is list of file + mod-time pairs
(define path-strings (append (list source-path) (define path-strings (append (list source-path)
(if template-path (list template-path) null) (if template-path (list template-path) null)
(or (get-directory-require-files source-path) null))) (or (get-directory-require-files source-path) null)))
(define project-root (world:current-project-root)) (define project-root (world:current-project-root))
;; can't use relative paths for cache keys because source files include `here-path` which is absolute. ;; can't use relative paths for cache keys because source files include `here-path` which is absolute.
;; problem is that cache could appear valid on another filesystem (based on relative pathnames & mod dates) ;; problem is that cache could appear valid on another filesystem (based on relative pathnames & mod dates)
@ -45,10 +45,26 @@
(world:current-meta-export) (dynamic-require path (world:current-meta-export))))) (world:current-meta-export) (dynamic-require path (world:current-meta-export)))))
(define ram-cache (make-hash)) ;; include this from 6.2 for compatibility back to 6.0 (formerly `make-parent-directory*`)
(define (make-parent-directory p)
(unless (path-string? p)
(raise-argument-error 'make-parent-directory "path-string?" p))
(define (make-directory* dir)
(let-values ([(base name dir?) (split-path dir)])
(when (and (path? base) (not (directory-exists? base)))
(make-directory* base))
(unless (directory-exists? dir)
(with-handlers ([exn:fail:filesystem:exists? void])
(make-directory dir)))))
(define-values (base name dir?) (split-path p))
(when (path? base)
(make-directory* base)))
(require sugar/debug) (define ram-cache (make-hash))
(define (cached-require path-string subkey) (define (cached-require path-string subkey)
(define path (with-handlers ([exn:fail? (λ _ (error 'cached-require (format "~a is not a valid path" path-string)))]) (define path (with-handlers ([exn:fail? (λ _ (error 'cached-require (format "~a is not a valid path" path-string)))])
(->complete-path path-string))) (->complete-path path-string)))
@ -62,7 +78,7 @@
;; use multiple pickup files to avoid locking issues. ;; use multiple pickup files to avoid locking issues.
;; pickup-file hierarchy just mirrors the project hierarchy. ;; pickup-file hierarchy just mirrors the project hierarchy.
(define dest-file (build-path cache-dir (path->string (find-relative-path (world:current-project-root) (string->path (format "~a.rktd" (key->source-path key))))))) (define dest-file (build-path cache-dir (path->string (find-relative-path (world:current-project-root) (string->path (format "~a.rktd" (key->source-path key)))))))
(make-parent-directory* dest-file) (make-parent-directory dest-file)
(hash-ref (hash-ref! ram-cache key (λ _ (hash-ref (hash-ref! ram-cache key (λ _
(cache-file dest-file (cache-file dest-file
#:exists-ok? #t #:exists-ok? #t

Loading…
Cancel
Save