From 0eb1282af72010b98c6603c4ba37cc95be8f6112 Mon Sep 17 00:00:00 2001 From: w6vvn Date: Wed, 10 Sep 2025 12:20:02 -0700 Subject: [PATCH] apply path assertions to existing path related commands --- palps.rkt | 67 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/palps.rkt b/palps.rkt index 8f99020..b332617 100755 --- a/palps.rkt +++ b/palps.rkt @@ -121,45 +121,50 @@ (session)))) (define (session) - (display "palps > ") - (flush-output) + (with-handlers + ([exn:fail:contract:illegal-path? + (λ (exn) + (displayln "cannot traverse higher than root"))]) - (match (regexp-match #px"(\\w+)\\s*(.*)" - (read-line (current-input-port) 'any)) - [(list _ "ls" _) - (for-each (λ (p) (displayln (path->string p))) - (directory-list)) - (flush-output)] + (display "palps > ") + (flush-output) - [(list _ "ed" name) - (let ([path (build-path (current-directory) - (string->path-element name))]) - (let ([path (if (file-exists? path) - (ed (our-make-temporary-file path)) + (match (regexp-match #px"(\\w+)\\s*(.*)" + (read-line (current-input-port) 'any)) + [(list _ "ls" _) + (for-each (λ (p) (displayln (path->string p))) + (directory-list)) + (flush-output)] + + [(list _ "ed" name) + (assert-confined-to-call-dir name) + + (let ([path (if (file-exists? name) + (ed (our-make-temporary-file name)) (ed))]) - (copy-file path name #:exists-ok? #t)))] + (copy-file path name #:exists-ok? #t))] - [(list _ "rm" name) - (let ([path (build-path (current-directory) - (string->path-element name))]) - (if (file-exists? path) - (delete-file path) + [(list _ "rm" name) + (assert-confined-to-call-dir name) + + (if (file-exists? name) + (delete-file name) (displayln "file does not exist")) - (flush-output))] + (flush-output)] - [(or (list _ "bye" _) - (list _ "b" _) - (list _ "quit" _) - (list _ "q" _)) - (displayln "goodbye") - (flush-output) - (exit)] + [(or (list _ "bye" _) + (list _ "b" _) + (list _ "quit" _) + (list _ "q" _)) + (displayln "goodbye") + (flush-output) + (exit)] - [else - (displayln "no such command") - (flush-output)]) + [else + (displayln "no such command") + (flush-output)])) (session)) -(session-startup) +;(session-startup)