prelude icon indicating copy to clipboard operation
prelude copied to clipboard

File permissions break sudoedit

Open Artefact2 opened this issue 3 years ago • 5 comments

I am running Prelude (emacs 27.2) on Arch Linux. It seems that when editing a file that looks like a bash script, something will automatically set +x on that file upon saving. Unfortunately that breaks sudoedit :

% echo $SUDO_EDITOR
emacsclient -nw -c
% sudoedit /etc/makepkg.conf 
sudoedit: /var/tmp/makepkgXXgBYd1E.conf: bad file mode: 0711
sudoedit: /etc/makepkg.conf left unmodified

Steps to reproduce:

% mkdir bar
% echo '#!/hint/bash\nfoo' > bar/foo.conf
% chmod 644 bar/foo.conf
% sudo chown root:root bar bar/foo.conf
% SUDO_EDITOR=emacsclient sudoedit bar/foo.conf
# (make any change then C-x C-s)
sudoedit: /var/tmp/fooXXiFtpLJ.conf: bad file mode: 0711
sudoedit: bar/foo.conf left unmodified

How can I disable this behaviour? Thanks.

Artefact2 avatar Sep 23 '21 21:09 Artefact2

There's a hook in prelude-editor.el that does this:

;; make a shell script executable automatically on save
(add-hook 'after-save-hook
          'executable-make-buffer-file-executable-if-script-p)

You can use remove-hook to remove it.

bbatsov avatar Sep 29 '21 10:09 bbatsov

Is there any way to make Emacs "smart" on this? I'm not sure what it'd look like exactly (I can't find where sudoedit changes any environment variables with light testing), but it might come in handy.

duckwork avatar Sep 29 '21 14:09 duckwork

We can have a more sophisticated hook - e.g. one that ignores certain files or runs additional predicate checks. It's easy to do, but I think it's going to be an overkill for most people.

bbatsov avatar Sep 30 '21 06:09 bbatsov

I figured as much -- I was scratching my head trying to figure out the predicate checks to make. Not sure if just checking whether the owner of the file is root is enough... but like you say, it's probably overkill.

duckwork avatar Sep 30 '21 14:09 duckwork

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

stale[bot] avatar Apr 16 '22 10:04 stale[bot]