[added read-library and validate-catalog procedures atsmyles@earthlink.net**20100429035636 Ignore-this: ad6aa0683b6c34b0c80a4de23037d655 ] hunk ./catalog.scm 182 - - +; given a uri or a version, returns the library form. +(define (read-library version-or-uri) + (cond + ((version? version-or-uri) (read-library (version-uri version-or-uri))) + ((string? version-or-uri) (read-library (uri version-or-uri))) + ((uri? version-or-uri) + (let* ((fragment (uri-fragment version-or-uri)) + (path (uri-part version-or-uri 'path)) + (reader (if fragment + (lambda () + (let loop ((i (string->number fragment))) + (if (= i 0) (read) (begin (read) (loop (- i 1)))))) + read))) + + (with-input-from-file path reader))) + (else (assertion-violation 'read-library "argument must be a version or a uri" version-or-uri)))) + +;validate a catalog. Checks that all the files are reachable and that the name and version of the library matches what is registered in the catalog. +(define (validate-catalog base-dir catalog) + (define (check-library library) + (for-each (lambda (v) + (cond + ((or (not (uri-scheme (version-uri v))) (not (eq? 'file (uri-scheme (version-uri v))))) + (assertion-violation 'ex:validate-catalog "We only support file based uris" library v)) + ((not (file-exists? (uri-part (version-uri v) 'path))) + (assertion-violation 'ex:validate-catalog "file not found!" library v)) + (else (call-with-values (lambda () (name&version (cadr (read-library v)))) + (lambda (name version) + (cond + ((not (equal? (library-name library) name)) + (assertion-violation 'validate-catalog "library name in catalog is not the same as library name in version!" name library)) + ((not (equal? (version-number v) version)) + (assertion-violation 'validate-catalog "library version in catalog does not have the same number as the library form" version v)))))) + )) + (library-versions library))) + + (let ((libraries (catalog->libraries base-dir catalog))) + (for-each check-library libraries) + catalog))