refuse an output naming the source

-o naming the input wrote over it, whatever was asked for.
This commit is contained in:
2026-10-19 10:23:59 +03:00
parent cc33e6abd8
commit 4b4f660f01
2 changed files with 19 additions and 0 deletions

View File

@@ -5,6 +5,7 @@
(chicken condition) ; handle-exceptions
(chicken file)
(chicken module)
(only (chicken pathname) normalize-pathname)
(chicken plist)
(chicken pretty-print)
(chicken process)
@@ -159,6 +160,12 @@
(dash? 'stdin)
(else (car inputs)))))
;;; Whether OUTPUT is the file INPUT, spelled however it is
(define (same-file? input output)
(and (string? input) (string? output) (not (stdout-output? output))
(equal? (normalize-pathname (to-absolute-pathname input))
(normalize-pathname (to-absolute-pathname output)))))
(define (stdout-output? output)
(or (eq? output 'default) (equal? output "-")))
@@ -282,6 +289,8 @@ status, which is ours to pass on."
(return #f))
(when (and (equal? output "-") (not (text-output? args)))
(error "-o - is stdout, which takes only -C, -m or --public-interface"))
(when (same-file? input output)
(error "-o names the input, and would overwrite its source" input))
;; Read time comes before everything, so the features have to be
;; in place before the first form is read
(current-features