* Deal with NNNpN versions as N.NN.N (eg, 103p1 => 1.03.1),
* Some more sane checks -- refuse old-style versions when it's higer than 380 * Added tests for these * Move sanity check to tests (where it will do the same since it runs every day) svn: r11397
This commit is contained in:
parent
b987dc265d
commit
b5fb8569cc
|
@ -5,6 +5,16 @@
|
||||||
|
|
||||||
(require version/utils)
|
(require version/utils)
|
||||||
|
|
||||||
|
;; sanity check
|
||||||
|
(unless (and (< (string->number (car (regexp-match #rx"^[0-9]+" (version)))) 49)
|
||||||
|
(integer? (version->integer (version))))
|
||||||
|
;; When this happens, we got to numbers that can be confused with old version
|
||||||
|
;; numbers, and the version/utils code should be modified. With the current
|
||||||
|
;; rate of changes, this should happen in more 150 years. Either programming
|
||||||
|
;; is probably done with a direct brain link, or this software has nobody to
|
||||||
|
;; fix it because everybody went back to the trees.
|
||||||
|
(error 'version/utils.ss "this file should be updated"))
|
||||||
|
|
||||||
(test #t valid-version? (version))
|
(test #t valid-version? (version))
|
||||||
(for-each (lambda (v+i) (test (cadr v+i) version->integer (car v+i)))
|
(for-each (lambda (v+i) (test (cadr v+i) version->integer (car v+i)))
|
||||||
'(;; legacy version scheme
|
'(;; legacy version scheme
|
||||||
|
@ -15,6 +25,9 @@
|
||||||
["123.4" 123004000]
|
["123.4" 123004000]
|
||||||
["49" 49000000] ; oldest legacy-version supported
|
["49" 49000000] ; oldest legacy-version supported
|
||||||
["103" 103000000]
|
["103" 103000000]
|
||||||
|
["103p1" 103001000] ; pN used as sub-sub-version
|
||||||
|
["380" #f] ; old style, but these versions never existed
|
||||||
|
["400" #f]
|
||||||
;; new version scheme
|
;; new version scheme
|
||||||
["4.0" 400000000]
|
["4.0" 400000000]
|
||||||
["4" #f] ; must have one decimal digit
|
["4" #f] ; must have one decimal digit
|
||||||
|
@ -47,6 +60,7 @@
|
||||||
["foo" #f]
|
["foo" #f]
|
||||||
["x.y" #f]
|
["x.y" #f]
|
||||||
["0" #f]
|
["0" #f]
|
||||||
|
["00" #f]
|
||||||
))
|
))
|
||||||
|
|
||||||
(report-errs)
|
(report-errs)
|
||||||
|
|
|
@ -41,33 +41,23 @@
|
||||||
|
|
||||||
;; returns an integer representing the version (XXYYZZZWWW) or #f if invalid
|
;; returns an integer representing the version (XXYYZZZWWW) or #f if invalid
|
||||||
;; works for pre v4 versions too
|
;; works for pre v4 versions too
|
||||||
(define (version->integer v)
|
(define (version->integer ver)
|
||||||
(cond
|
(define m
|
||||||
[(regexp-match-positions #rx"^(?:0|[1-9][0-9]*)" v) ; takes all digits
|
(regexp-match-positions #rx"^(?:0|[1-9][0-9]*)" ver)) ; takes all digits
|
||||||
=> (lambda (m)
|
;; translate old versions to new-style versions
|
||||||
(let* (;; translate to a new-style version
|
(define n (and m (string->number (substring ver 0 (cdar m)))))
|
||||||
[n (string->number (substring v 0 (cdar m)))]
|
(define v
|
||||||
[v (if (< n 49)
|
(cond [(not n) #f]
|
||||||
v
|
;; new versions
|
||||||
|
[(< n 49) ver]
|
||||||
|
;; old versions (earliest useful is 49, changed at 3.99)
|
||||||
|
[(<= 49 n 379)
|
||||||
(let-values ([(q r) (quotient/remainder n 100)])
|
(let-values ([(q r) (quotient/remainder n 100)])
|
||||||
;; put numbers and possible .N leftover
|
;; put numbers and a possible .N leftover (done for pN too)
|
||||||
(format "~a.~a~a" q r (substring v (cdar m)))))])
|
(format "~a.~a~a" q r
|
||||||
(and (valid-version? v)
|
(regexp-replace #rx"^p" (substring ver (cdar m)) ".")))]
|
||||||
(let ([l (version->list v)])
|
;; bad strings
|
||||||
(let loop ([v (car l)]
|
|
||||||
[l (cdr l)]
|
|
||||||
[f '(100 1000 1000)])
|
|
||||||
(if (null? l)
|
|
||||||
v
|
|
||||||
(loop (+ (* v (car f)) (car l)) (cdr l) (cdr f))))))))]
|
|
||||||
[else #f]))
|
[else #f]))
|
||||||
|
(and (valid-version? v)
|
||||||
;; general sanity check, performed once when loaded
|
(foldl (lambda (ver mul acc) (+ ver (* mul acc))) 0
|
||||||
(unless (and (< (string->number (car (regexp-match #rx"^[0-9]+" (version)))) 49)
|
(version->list v) '(0 100 1000 1000))))
|
||||||
(integer? (version->integer (version))))
|
|
||||||
;; When this happens, we got to numbers that can be confused with old version
|
|
||||||
;; numbers, and the above code should be modified. With the current rate of
|
|
||||||
;; changes, this should happen in more 150 years. Either programming is
|
|
||||||
;; probably done with a direct brain link, or this software has nobody to fix
|
|
||||||
;; it because everybody went back to the trees.
|
|
||||||
(error 'version/utils.ss "this file should be updated"))
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user