From 5191da2b1e99984acf30c800997b370b831aa7eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= <hugo@hornquist.se> Date: Mon, 12 Aug 2019 00:33:21 +0200 Subject: [PATCH] Disallow access to missing directories. --- mediawikifs.scm | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/mediawikifs.scm b/mediawikifs.scm index c081981..865cde4 100644 --- a/mediawikifs.scm +++ b/mediawikifs.scm @@ -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))) )) -- GitLab