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))))
(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)