all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Eli Zaretskii <eliz@gnu.org>, Lars Ingebrigtsen <larsi@gnus.org>,
	Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 60146@debbugs.gnu.org
Subject: bug#60146: file-exists-in-trash-p needs better name or semantics
Date: Sat, 17 Dec 2022 11:57:39 -0800	[thread overview]
Message-ID: <4b872c57-99fd-dc8c-a121-7f19be0f9d49@cs.ucla.edu> (raw)
In-Reply-To: <83a63mifgu.fsf@gnu.org>

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

On 12/17/22 00:47, Eli Zaretskii wrote:
> I don't really mind renaming that function, but the reason I called it
> like I did was that apparently no one needed such a functionality in
> Emacs until now,

I have a bit of a different take. First, there's adequate functionality 
in Emacs now if we don't mind inefficiency, and it's already used; just 
call file-attributes. (Gnus does this, in nnmaildir-unlink at least, and 
I expect there are other uses.) Second, I wouldn't be surprised if other 
uses of file-exists-p have problems similar to the one you found in 
move-file-to-trash. Not that any of us have time to go scout for them 
right now.

It's a minor point. Still, the name file-exists-in-trash-p really needs 
to go somehow as it's not a name that should be user-visible. How about 
the attached patch?


[-- Attachment #2: 0001-Remove-file-exists-in-trash-p.patch --]
[-- Type: text/x-patch, Size: 2525 bytes --]

From adcf3112e72431e4c4a2610941afcc238e7dd243 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sat, 17 Dec 2022 11:54:46 -0800
Subject: [PATCH] Remove file-exists-in-trash-p

* lisp/files.el (file-exists-in-trash-p): Remove, as this name is
not suitable for users.  All uses replaced by file-attributes,
which is good enough here.
---
 lisp/files.el | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/lisp/files.el b/lisp/files.el
index c74e7e808e4..149480a6f10 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -8467,14 +8467,6 @@ trash--hexify-table
 
 (declare-function system-move-file-to-trash "w32fns.c" (filename))
 
-(defun file-exists-in-trash-p (filename)
-  "Return non-nil if FILENAME exists in the trash.
-
-This is like `file-exists-p', but it also returns non-nil
-if FILENAME is a dangling symlink, to allow trashing such files."
-  (or (file-exists-p filename)
-      (file-symlink-p filename)))
-
 (defun move-file-to-trash (filename)
   "Move the file (or directory) named FILENAME to the trash.
 When `delete-by-moving-to-trash' is non-nil, this function is
@@ -8505,7 +8497,7 @@ move-file-to-trash
 	   (unless (file-directory-p trash-dir)
 	     (make-directory trash-dir t))
 	   ;; Ensure that the trashed file-name is unique.
-	   (if (file-exists-in-trash-p new-fn)
+	   (if (file-attributes new-fn)
 	       (let ((version-control t)
 		     (backup-directory-alist nil))
 		 (setq new-fn (car (find-backup-file-name new-fn)))))
@@ -8582,7 +8574,7 @@ move-file-to-trash
                  ;; We're checking further down whether the info file
                  ;; exists, but the file name may exist in the trash
                  ;; directory even if there is no info file for it.
-                 (when (file-exists-in-trash-p
+                 (when (file-attributes
                         (file-name-concat trash-files-dir files-base))
                    (setq overwrite t
                          files-base (file-name-nondirectory
@@ -8620,7 +8612,7 @@ move-file-to-trash
 		 (let ((delete-by-moving-to-trash nil)
 		       (new-fn (file-name-concat trash-files-dir files-base)))
                    (if (or (not is-directory)
-                           (not (file-exists-in-trash-p new-fn)))
+                           (not (file-attributes new-fn)))
                        (rename-file fn new-fn overwrite)
                      (copy-directory fn
                                      (file-name-as-directory new-fn)
-- 
2.38.1


  parent reply	other threads:[~2022-12-17 19:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-17  5:17 bug#60146: file-exists-in-trash-p needs better name or semantics Paul Eggert
2022-12-17  8:47 ` Eli Zaretskii
2022-12-17 15:51   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-17 17:45     ` Eli Zaretskii
2022-12-17 19:57   ` Paul Eggert [this message]
2022-12-17 20:09     ` Eli Zaretskii
2022-12-17 23:55       ` Paul Eggert
2022-12-17 10:01 ` Michael Albinus

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

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

  git send-email \
    --in-reply-to=4b872c57-99fd-dc8c-a121-7f19be0f9d49@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=60146@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=larsi@gnus.org \
    --cc=monnier@iro.umontreal.ca \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.