/usr/share/racket/collects/setup/link.rkt is in racket-common 6.1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | #lang racket/base
(require racket/file
racket/path
setup/dirs
setup/collection-name)
(provide links)
(define (links #:error [error error]
#:user? [user? #t]
#:user-version [user-version (and user?
(get-installation-name))]
#:file [in-file #f]
#:name [name #f]
#:version-regexp [version-regexp #f]
#:root? [root? #f]
#:static-root? [static-root? #f]
#:remove? [remove? #f]
#:show? [show? #f]
#:repair? [repair? #f]
#:with-path? [with-path? #f]
. dirs)
(define (check-name name)
(unless (collection-name-element? name)
(error 'links "name is not valid as a top-level collection name: ~e"
name)))
(when name
(check-name name))
(define file (or in-file
(if user?
(build-path (find-system-path 'addon-dir) user-version "links.rktd")
(find-links-file))))
(define need-repair? #f)
(define (content-error str v)
(if repair?
(begin
(log-warning (format "~a~e" str v))
(set! need-repair? #t)
#f)
(error 'links "~a~e" str v)))
(define table
(with-handlers ([exn:fail?
(lambda (exn)
(let ([msg (format
"error reading from link file: ~s: ~a"
file
(exn-message exn))])
(if repair?
(begin
(log-warning msg)
(set! need-repair? #t)
null)
(error 'links "~a" msg))))])
(if (and file (file-exists? file))
(let ([l (with-input-from-file file read)])
(if (list? l)
(for/list ([e (in-list l)]
#:when
(or (and (list? e)
(or (= 2 (length e))
(= 3 (length e))))
(content-error "entry is a not a 2- or 3-element list: " e))
#:when
(or (or (string? (car e))
(eq? 'root (car e))
(eq? 'static-root (car e)))
(content-error "entry's first element is not a string, 'root, or 'static-root: " e))
#:when
(or (path-string? (cadr e))
(content-error "entry's second element is not a path string: " e))
#:when
(or (null? (cddr e))
(regexp? (caddr e))
(content-error "entry's third element is not a version regexp: " e)))
e)
(begin
(content-error "content is not a list: " l)
null)))
null)))
(define mapped (make-hash))
(define (add-entry! e)
(hash-set! mapped
(car e)
(cons (cdr e) (hash-ref mapped (car e) null))))
(for ([e (in-list table)]) (add-entry! e))
(define file-dir
(and file
(let-values ([(base name dir?)
(split-path (simplify-path
(path->complete-path file)))])
base)))
(define (simplify p)
(simplify-path (path->complete-path p file-dir)))
(define new-table
(reverse
(for/fold ([table (reverse table)]) ([d (in-list
(if (and (null? dirs)
name)
'(#f)
dirs))])
(let* ([dp (and d
(find-relative-path file-dir
(simplify-path
(path->complete-path d))
#:more-than-root? #t))]
[a-name (if root?
(if static-root?
'static-root
'root)
(and d
(or name
(let-values ([(base name dir?) (split-path dp)])
(path-element->string name)))))]
[rx version-regexp]
[d (and dp (path->string dp))]
[sd (and d (simplify d))])
(unless remove?
(unless (directory-exists? sd)
(error 'links
"no such directory for link: ~a"
sd)))
(if remove?
(filter (lambda (e)
(or (and d
(not (equal? (simplify (cadr e))
sd)))
(and name
(not (equal? (car e) name)))
(and root?
(not (or (eq? (car e) 'root)
(eq? (car e) 'static-root))))
(and version-regexp
(pair? (cddr e))
(not (equal? (caddr e) version-regexp)))))
table)
(let ([l (hash-ref mapped a-name null)]
[e (list* a-name
d
(if rx (list rx) null))])
(if (member (cdr e) l)
table
(let ()
(when (string? a-name)
(check-name a-name))
(add-entry! e)
(cons e table)))))))))
(unless (and (not need-repair?)
(equal? new-table table))
(let ([dir (let-values ([(base name dir?) (split-path file)])
base)])
(make-directory* dir)
(call-with-atomic-output-file
file
(lambda (o tmp-path)
(parameterize ([current-output-port o])
(printf "(")
(let loop ([l new-table] [prefix ""])
(cond
[(null? l) (printf ")\n")]
[else
(printf "~a~s" prefix (car l))
(unless (null? (cdr l)) (newline))
(loop (cdr l) " ")])))))))
(when show?
(for ([e (in-list new-table)])
(printf " ~a~s path: ~s~a\n"
(if (or (eq? (car e) 'root)
(eq? (car e) 'static-root))
""
"collection: ")
(car e)
(path->string (simplify (cadr e)))
(if (null? (cddr e))
""
(format " version: ~s"
(caddr e))))))
(if remove?
;; return list of removed entries:
(filter (lambda (e) (not (member e new-table))) table)
(if root?
;; Return root paths:
(for/list ([e (in-list new-table)]
#:when (or (eq? 'root (car e))
(eq? 'static-root (car e)))
#:when (or (null? (cddr e))
(regexp-match? (caddr e) (version))))
(simplify (cadr e)))
;; Return list of collections mapped for this version:
(let ([ht (make-hash)])
(for ([e (in-list new-table)])
(when (and (string? (car e))
(or (null? (cddr e))
(regexp-match? (caddr e) (version))))
(hash-set! ht (if with-path?
(cons (car e) (simplify (cadr e)))
(car e))
#t)))
(hash-keys ht)))))
|