fix(cli): ensure local file/dir permissions

May catch edge cases where profile directories are created with
over-restrictive permissions (mentioned in #5832).

Ref: #5832
This commit is contained in:
Henrik Lissner 2023-12-05 17:12:40 -05:00
parent 8352562b2c
commit be90021330
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -1050,9 +1050,9 @@ considered as well."
"\n"))) "\n")))
(print! (warn "Wrote extended straight log to %s") (print! (warn "Wrote extended straight log to %s")
(path (let ((coding-system-for-write 'utf-8-auto)) (path (let ((coding-system-for-write 'utf-8-auto))
(with-temp-file error-file (with-file-modes #o600
(insert-buffer-substring (straight--process-buffer))) (with-temp-file error-file
(set-file-modes error-file #o600) (insert-buffer-substring (straight--process-buffer))))
error-file)))) error-file))))
((eq type 'error) ((eq type 'error)
(let* ((generic? (eq (car data) 'error)) (let* ((generic? (eq (car data) 'error))
@ -1123,11 +1123,12 @@ See `doom-cli-log-file-format' for details."
(let* ((buffer (doom-cli-context-stderr context)) (let* ((buffer (doom-cli-context-stderr context))
(file (doom-cli--output-file "log" context))) (file (doom-cli--output-file "log" context)))
(when (> (buffer-size buffer) 0) (when (> (buffer-size buffer) 0)
(make-directory (file-name-directory file) t) (with-file-modes #o700
(with-temp-file file (make-directory (file-name-directory file) t))
(insert-buffer-substring buffer) (with-file-modes #o600
(ansi-color-filter-region (point-min) (point-max))) (with-temp-file file
(set-file-modes file #o600))))) (insert-buffer-substring buffer)
(ansi-color-filter-region (point-min) (point-max))))))))
(defun doom-cli--output-benchmark-h (context) (defun doom-cli--output-benchmark-h (context)
"Write this session's benchmark to stdout or stderr, depending. "Write this session's benchmark to stdout or stderr, depending.
@ -1351,10 +1352,11 @@ ARGS are options passed to less. If DOOMPAGER is set, ARGS are ignored."
((let ((tmpfile (doom-cli--output-file 'output context)) ((let ((tmpfile (doom-cli--output-file 'output context))
(coding-system-for-write 'utf-8-auto)) (coding-system-for-write 'utf-8-auto))
(make-directory (file-name-directory tmpfile) t) (with-file-modes #o700
(with-temp-file tmpfile (make-directory (file-name-directory tmpfile) t))
(insert-buffer-substring (doom-cli-context-stdout context))) (with-file-modes #o600
(set-file-modes tmpfile #o600) (with-temp-file tmpfile
(insert-buffer-substring (doom-cli-context-stdout context))))
(doom-cli--restart (doom-cli--restart
(format "%s <%s; rm -f%s %s" (format "%s <%s; rm -f%s %s"
(or pager (or pager