Commit 5191da2b authored by Hugo Hörnquist's avatar Hugo Hörnquist

Disallow access to missing directories.

parent 6c5f13e3
......@@ -76,6 +76,7 @@
'()))))
;; returns string list of all categories
(define (all-categories #!optional continue-from)
(let* ((page _ _ (get-xml-page (category-uri continue-from))))
(append (map sxml:text ((sxpath '(// allcategories c)) page))
......@@ -95,6 +96,7 @@
`((cmcontinue . ,continue-from))
'()))))
;; Get string list of pages belonging to category
(define (all-pages-in-category category-name #!optional continue-from)
(let* ((page _ _ (get-xml-page (category-members-uri
category-name continue-from))))
......@@ -125,9 +127,10 @@
(map (cut cons <> 'not-downloaded)
(all-categories))))
;; wrapper around `all-pages-in-category', which also updates hash-map
(define (category-page-names category)
(case (hash-table-ref/default categories category 'no-such-page)
((no-such-page) '())
((no-such-page) #f)
((not-downloaded)
(let ((pages (all-pages-in-category category)))
(set! (hash-table-ref categories category) pages)
......@@ -136,10 +139,12 @@
(define pages (make-hash-table))
;; Get id field of page object
(define (page-id page)
(let ((id-str (sxml:text ((sxpath '(// mw:page mw:id)) page))))
(read (open-input-string id-str))))
;; Get byte length field of page object
(define (page-length page)
(let ((length-str (sxml:text ((sxpath '(// mw:page // mw:text @ bytes)) page))))
(read (open-input-string length-str))))
......@@ -159,9 +164,9 @@
(let ((path (string-split path-str "/")))
(cons* "." ".."
(map ->string
(cond ((null? path) (hash-table-keys categories))
((= 1 (length path)) (category-page-names (car path)))
(else '()))))))
(cond [(null? path) (hash-table-keys categories)]
[(= 1 (length path)) (category-page-names (car path))]
[else '()])))))
getattr: (lambda (path-str)
(print path-str)
......@@ -174,17 +179,17 @@
(current-group-id)
(hash-table-size categories)
0 0 0))
((= 1 (length path))
(let ((sub-pages (category-page-names (car path))))
(if (null? sub-pages)
(vector (bitwise-ior file/dir #o555)
2 0 0 0 0 0 0)
(vector (bitwise-ior file/dir #o555)
2
(current-user-id)
(current-group-id)
(length sub-pages)
0 0 0))))
(and sub-pages
(vector (bitwise-ior file/dir #o555)
2
(current-user-id)
(current-group-id)
(length sub-pages)
0 0 0))))
(else
(let* ((page (get-page pages (cadr path))))
(and page
......@@ -200,6 +205,7 @@
(else (get-page pages (cadr path))))))
read: (lambda (handle size offset)
;; TODO handle size and offset
(sxml:text
((sxpath '(// mw:page // mw:text)) handle)))
))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment