diff options
author | Philipp Stephani <phst@google.com> | 2020-12-13 17:13:50 +0100 |
---|---|---|
committer | Philipp Stephani <phst@google.com> | 2020-12-13 17:17:21 +0100 |
commit | fe50a8b9ba79b4ac14a3a352d8bf84eaee4f2122 (patch) | |
tree | 0b0b990f0f49f2ad652c2506caa7e5b15add75a3 /lisp/emacs-lisp | |
parent | 897b8561cdc856fb40b2a3c6f29230849aaf4a34 (diff) | |
download | emacs-fe50a8b9ba79b4ac14a3a352d8bf84eaee4f2122.tar.gz emacs-fe50a8b9ba79b4ac14a3a352d8bf84eaee4f2122.tar.bz2 emacs-fe50a8b9ba79b4ac14a3a352d8bf84eaee4f2122.zip |
Byte compilation: handle case where the output file is a mountpoint.
See Bug#44631. While testing for a readonly output directory has
slightly different semantics, in practice they should cover cases
where Emacs is sandboxed and can only write to the destination file,
not its directory.
* lisp/emacs-lisp/bytecomp.el (byte-compile-file): Handle the case
where the output directory is not writable.
* test/lisp/emacs-lisp/bytecomp-tests.el
(bytecomp-tests--not-writable-directory)
(bytecomp-tests--dest-mountpoint): New unit tests.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/bytecomp.el | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 51accc08654..e23bb9f5e6e 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -1963,7 +1963,11 @@ See also `emacs-lisp-byte-compile-and-load'." (insert "\n") ; aaah, unix. (cond ((null target-file) nil) ;We only wanted the warnings! - ((file-writable-p target-file) + ((and (file-writable-p target-file) + ;; We attempt to create a temporary file in the + ;; target directory, so the target directory must be + ;; writable. + (file-writable-p (file-name-directory target-file))) ;; We must disable any code conversion here. (let* ((coding-system-for-write 'no-conversion) ;; Write to a tempfile so that if another Emacs @@ -1992,6 +1996,14 @@ See also `emacs-lisp-byte-compile-and-load'." ;; deleting target-file before writing it. (rename-file tempfile target-file t)) (or noninteractive (message "Wrote %s" target-file))) + ((file-writable-p target-file) + ;; In case the target directory isn't writable (see e.g. Bug#44631), + ;; try writing to the output file directly. We must disable any + ;; code conversion here. + (let ((coding-system-for-write 'no-conversion)) + (with-file-modes (logand (default-file-modes) #o666) + (write-region (point-min) (point-max) target-file nil 1))) + (or noninteractive (message "Wrote %s" target-file))) (t ;; This is just to give a better error message than write-region (let ((exists (file-exists-p target-file))) |