apply path assertions to existing path related commands

This commit is contained in:
2025-09-10 12:20:02 -07:00
parent 9b492b52fe
commit 0eb1282af7

View File

@@ -121,45 +121,50 @@
(session)))) (session))))
(define (session) (define (session)
(display "palps > ") (with-handlers
(flush-output) ([exn:fail:contract:illegal-path?
(λ (exn)
(displayln "cannot traverse higher than root"))])
(match (regexp-match #px"(\\w+)\\s*(.*)" (display "palps > ")
(read-line (current-input-port) 'any)) (flush-output)
[(list _ "ls" _)
(for-each (λ (p) (displayln (path->string p)))
(directory-list))
(flush-output)]
[(list _ "ed" name) (match (regexp-match #px"(\\w+)\\s*(.*)"
(let ([path (build-path (current-directory) (read-line (current-input-port) 'any))
(string->path-element name))]) [(list _ "ls" _)
(let ([path (if (file-exists? path) (for-each (λ (p) (displayln (path->string p)))
(ed (our-make-temporary-file path)) (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))]) (ed))])
(copy-file path name #:exists-ok? #t)))] (copy-file path name #:exists-ok? #t))]
[(list _ "rm" name) [(list _ "rm" name)
(let ([path (build-path (current-directory) (assert-confined-to-call-dir name)
(string->path-element name))])
(if (file-exists? path) (if (file-exists? name)
(delete-file path) (delete-file name)
(displayln "file does not exist")) (displayln "file does not exist"))
(flush-output))] (flush-output)]
[(or (list _ "bye" _) [(or (list _ "bye" _)
(list _ "b" _) (list _ "b" _)
(list _ "quit" _) (list _ "quit" _)
(list _ "q" _)) (list _ "q" _))
(displayln "goodbye") (displayln "goodbye")
(flush-output) (flush-output)
(exit)] (exit)]
[else [else
(displayln "no such command") (displayln "no such command")
(flush-output)]) (flush-output)]))
(session)) (session))
(session-startup) ;(session-startup)