unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Michael Albinus via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 70421@debbugs.gnu.org
Cc: wurfkreuz@mail.ru
Subject: bug#70421: eshell/sudo with delete-by-moving-to-trash
Date: Wed, 17 Apr 2024 10:28:56 +0200	[thread overview]
Message-ID: <87frvk9yuv.fsf@gmx.de> (raw)
In-Reply-To: <1713264991.521724415@f148.i.mail.ru> ("кппкяып япвквкп via \"Bug reports for GNU Emacs, the Swiss army knife of text editors\""'s message of "Tue, 16 Apr 2024 13:56:31 +0300")

[-- Attachment #1: Type: text/plain, Size: 2418 bytes --]

кппкяып япвквкп via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs@gnu.org> writes:

Hi,

> In GNU Emacs 30.0.50 on Arch Linux, I encountered a permission issue
> when trying to delete a file with elevated privileges using `eshell/rm`
> in combination with `delete-by-moving-to-trash` enabled. This suggests
> that the deletion process is not fully "TRAMP aware."
>  
> Steps to reproduce:
>  
> 1. emacs -Q
> 2. ~ $ (setq delete-by-moving-to-trash t)
> t
> 3. ~ $ (require 'em-tramp)
> em-tramp
> 4. ~ $ eshell/sudo touch /etc/bugtestfile
> 5. ~ $ eshell/sudo rm /etc/bugtestfile
> Cannot move /etc/bugtestfile to trash: Permission denied
>  
>  
> Expected behavior:
>  
> I expect emacs to handle this situation by using
> /root/.local/share/Trash
> instead of /home/username/.local/share/Trash.

No. Without special preparation, remote files are moved to the local
trash directory, /home/username/.local/share/Trash this case. See the
Tramp manual (info "(tramp) Frequently Asked Questions")

--8<---------------cut here---------------start------------->8---
   • Where are remote files trashed to?

     Emacs can trash file instead of deleting them, *note Trashing:
     (emacs)Misc File Ops.  Remote files are always trashed to the local
     trash, except the user option
     ‘remote-file-name-inhibit-delete-by-moving-to-trash’ is non-‘nil’,
     or it is a remote encrypted file (*note Keeping files encrypted::),
     which are deleted anyway.
--8<---------------cut here---------------end--------------->8---

However, we could try to configure it. There is the variable
trash-directory, which is nil by default. We cannot give it another
(remote) directory name, because it would be used always. Instead, we
use connection-local variables. In your case, I recommend to set

--8<---------------cut here---------------start------------->8---
(connection-local-set-profile-variables
 'remote-trash-directory
 '((trash-directory . "/sudo::~/.local/share/Trash")))

(connection-local-set-profiles
 `(:application tramp :protocol "sudo" :machine ,system-name)
 'remote-trash-directory)
--8<---------------cut here---------------end--------------->8---

Now we must teach Emacs, that trash-directory should respect
connection-local values. The following patch of files.el does this for
us:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 786 bytes --]

diff --git a/lisp/files.el b/lisp/files.el
index 1e11dd44bad..447661dba5b 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -8812,9 +8812,10 @@ move-file-to-trash
   ;; If `system-move-file-to-trash' is defined, use it.
   (cond ((fboundp 'system-move-file-to-trash)
 	 (system-move-file-to-trash filename))
-        (trash-directory
+        ((connection-local-value trash-directory)
 	 ;; If `trash-directory' is non-nil, move the file there.
-	 (let* ((trash-dir   (expand-file-name trash-directory))
+	 (let* ((trash-dir   (expand-file-name
+                              (connection-local-value trash-directory)))
 		(fn          (directory-file-name (expand-file-name filename)))
 		(new-fn      (concat (file-name-as-directory trash-dir)
 				     (file-name-nondirectory fn))))

[-- Attachment #3: Type: text/plain, Size: 76 bytes --]


Could you, please, check whether it works for you?

Best regards, Michael.

  reply	other threads:[~2024-04-17  8:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-16 10:56 bug#70421: eshell/sudo with delete-by-moving-to-trash кппкяып япвквкп via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-17  8:28 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
     [not found] ` <1713860473.974078720@f344.i.mail.ru>
     [not found]   ` <1713862021.988479672@f344.i.mail.ru>
     [not found]     ` <1713864071.650225732@f510.i.mail.ru>
2024-04-23 12:01       ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87frvk9yuv.fsf@gmx.de \
    --to=bug-gnu-emacs@gnu.org \
    --cc=70421@debbugs.gnu.org \
    --cc=michael.albinus@gmx.de \
    --cc=wurfkreuz@mail.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).