make blueboxes library work properly when the blueboxes.rktd files content changes
This commit is contained in:
parent
e6630f0e97
commit
ec50ab1afe
|
@ -15,7 +15,14 @@
|
||||||
[fetch-blueboxes-method-tags (->* (symbol?) (#:blueboxes-cache blueboxes-cache?)
|
[fetch-blueboxes-method-tags (->* (symbol?) (#:blueboxes-cache blueboxes-cache?)
|
||||||
(listof method-tag?))]))
|
(listof method-tag?))]))
|
||||||
|
|
||||||
|
|
||||||
|
;; offset : (or/c exact-nonnegative-integer? #f)
|
||||||
|
;; tag-ht : (or/c valid-blueboxes-info? #f)
|
||||||
|
;; mod-time : (or/c exact-nonnegative-integer? #f)
|
||||||
|
(struct bluebox-info (blueboxes.rktd [offset #:mutable] [tag-ht #:mutable] [mod-time #:mutable]))
|
||||||
|
|
||||||
(struct blueboxes-cache (info-or-paths method->tags) #:mutable)
|
(struct blueboxes-cache (info-or-paths method->tags) #:mutable)
|
||||||
|
|
||||||
(define (make-blueboxes-cache
|
(define (make-blueboxes-cache
|
||||||
populate?
|
populate?
|
||||||
#:blueboxes-dirs
|
#:blueboxes-dirs
|
||||||
|
@ -45,16 +52,17 @@
|
||||||
(define (fetch-strs-for-single-tag tag cache)
|
(define (fetch-strs-for-single-tag tag cache)
|
||||||
(populate-cache! cache)
|
(populate-cache! cache)
|
||||||
(for/or ([ent (in-list (blueboxes-cache-info-or-paths cache))])
|
(for/or ([ent (in-list (blueboxes-cache-info-or-paths cache))])
|
||||||
(define offset+lens (hash-ref (list-ref ent 2) tag #f))
|
(check-and-update-bluebox-info! ent)
|
||||||
|
(match ent
|
||||||
|
[(bluebox-info blueboxes.rktd offset tag-ht _)
|
||||||
|
(define offset+lens (hash-ref tag-ht tag #f))
|
||||||
(cond
|
(cond
|
||||||
[offset+lens
|
[offset+lens
|
||||||
(define lines
|
(define lines
|
||||||
(apply
|
(apply
|
||||||
append
|
append
|
||||||
(for/list ([offset+len (in-list offset+lens)])
|
(for/list ([offset+len (in-list offset+lens)])
|
||||||
(define fn (list-ref ent 0))
|
(call-with-input-file blueboxes.rktd
|
||||||
(define offset (list-ref ent 1))
|
|
||||||
(call-with-input-file fn
|
|
||||||
(λ (port)
|
(λ (port)
|
||||||
(port-count-lines! port)
|
(port-count-lines! port)
|
||||||
(file-position port (+ (car offset+len) offset))
|
(file-position port (+ (car offset+len) offset))
|
||||||
|
@ -63,7 +71,7 @@
|
||||||
(cond
|
(cond
|
||||||
[(ormap eof-object? lines) #f]
|
[(ormap eof-object? lines) #f]
|
||||||
[else lines])]
|
[else lines])]
|
||||||
[else #f])))
|
[else #f])])))
|
||||||
|
|
||||||
(define (fetch-blueboxes-method-tags sym #:blueboxes-cache [cache (make-blueboxes-cache #f)])
|
(define (fetch-blueboxes-method-tags sym #:blueboxes-cache [cache (make-blueboxes-cache #f)])
|
||||||
(populate-cache! cache)
|
(populate-cache! cache)
|
||||||
|
@ -78,9 +86,9 @@
|
||||||
|
|
||||||
(define (compute-methods-table lst)
|
(define (compute-methods-table lst)
|
||||||
(define meth-ht (make-hash))
|
(define meth-ht (make-hash))
|
||||||
(for ([three-tuple (in-list lst)])
|
(for ([a-bluebox-info (in-list lst)])
|
||||||
(match three-tuple
|
(match a-bluebox-info
|
||||||
[`(,file-path ,i ,tag-ht)
|
[(bluebox-info blueboxes.rktd offset tag-ht mod-time)
|
||||||
(for ([(tag val) (in-hash tag-ht)])
|
(for ([(tag val) (in-hash tag-ht)])
|
||||||
(when (method-tag? tag)
|
(when (method-tag? tag)
|
||||||
(define-values (class/intf meth) (get-class/interface-and-method tag))
|
(define-values (class/intf meth) (get-class/interface-and-method tag))
|
||||||
|
@ -93,7 +101,22 @@
|
||||||
values
|
values
|
||||||
(for*/list ([doc-dir-name (in-list blueboxes-dirs)])
|
(for*/list ([doc-dir-name (in-list blueboxes-dirs)])
|
||||||
(define blueboxes.rktd (build-path doc-dir-name "blueboxes.rktd"))
|
(define blueboxes.rktd (build-path doc-dir-name "blueboxes.rktd"))
|
||||||
|
(define a-bluebox-info (bluebox-info blueboxes.rktd #f #f #f))
|
||||||
|
(populate-bluebox-info! a-bluebox-info)
|
||||||
|
a-bluebox-info)))
|
||||||
|
|
||||||
|
(define (check-and-update-bluebox-info! a-bluebox-info)
|
||||||
|
(match a-bluebox-info
|
||||||
|
[(bluebox-info blueboxes.rktd offset tag-ht mod-time)
|
||||||
|
(when (or (not mod-time)
|
||||||
(and (file-exists? blueboxes.rktd)
|
(and (file-exists? blueboxes.rktd)
|
||||||
|
(not (mod-time . = . (file-or-directory-modify-seconds blueboxes.rktd)))))
|
||||||
|
(populate-bluebox-info! a-bluebox-info))]))
|
||||||
|
|
||||||
|
(define (populate-bluebox-info! a-bluebox-info)
|
||||||
|
(define blueboxes.rktd (bluebox-info-blueboxes.rktd a-bluebox-info))
|
||||||
|
(cond
|
||||||
|
[(file-exists? blueboxes.rktd)
|
||||||
(call-with-input-file blueboxes.rktd
|
(call-with-input-file blueboxes.rktd
|
||||||
(λ (port)
|
(λ (port)
|
||||||
(port-count-lines! port)
|
(port-count-lines! port)
|
||||||
|
@ -111,11 +134,14 @@
|
||||||
"blueboxes info didn't have the right shape: ~s"
|
"blueboxes info didn't have the right shape: ~s"
|
||||||
candidate))
|
candidate))
|
||||||
candidate))
|
candidate))
|
||||||
(and desed
|
(set-bluebox-info-offset! a-bluebox-info (and desed (+ (string->number first-line) pos)))
|
||||||
(list blueboxes.rktd
|
(set-bluebox-info-tag-ht! a-bluebox-info desed)
|
||||||
(+ (string->number first-line) pos)
|
(set-bluebox-info-mod-time! a-bluebox-info
|
||||||
desed))))))))
|
(file-or-directory-modify-seconds blueboxes.rktd))))]
|
||||||
|
[else
|
||||||
|
(set-bluebox-info-offset! a-bluebox-info #f)
|
||||||
|
(set-bluebox-info-tag-ht! a-bluebox-info #f)
|
||||||
|
(set-bluebox-info-mod-time! a-bluebox-info #f)]))
|
||||||
|
|
||||||
(define valid-blueboxes-info?
|
(define valid-blueboxes-info?
|
||||||
(hash/c
|
(hash/c
|
||||||
|
|
Loading…
Reference in New Issue
Block a user