From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#59986: 30.0.50; Can't trash file with broken symbolic link Date: Thu, 15 Dec 2022 18:07:45 +0200 Message-ID: <83y1r8k5v2.fsf@gnu.org> References: <86cz8p15dj.fsf@protected.rcdrun.com> <871qp42c77.fsf@web.de> <83lenbpj9o.fsf@gnu.org> <83359jpdm1.fsf@gnu.org> <837cyunp81.fsf@gnu.org> <87tu1xttgv.fsf@web.de> <83v8mdkunj.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10660"; mail-complaints-to="usenet@ciao.gmane.io" Cc: michael_heerdegen@web.de, 59986@debbugs.gnu.org To: Jean Louis Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 15 17:08:24 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p5qmU-0002U7-L6 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 15 Dec 2022 17:08:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5qmC-0006pf-D8; Thu, 15 Dec 2022 11:08:04 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5qmA-0006pQ-Sp for bug-gnu-emacs@gnu.org; Thu, 15 Dec 2022 11:08:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p5qmA-0000NO-KW for bug-gnu-emacs@gnu.org; Thu, 15 Dec 2022 11:08:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p5qm9-00086B-Va for bug-gnu-emacs@gnu.org; Thu, 15 Dec 2022 11:08:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 15 Dec 2022 16:08:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59986 X-GNU-PR-Package: emacs Original-Received: via spool by 59986-submit@debbugs.gnu.org id=B59986.167112047631124 (code B ref 59986); Thu, 15 Dec 2022 16:08:01 +0000 Original-Received: (at 59986) by debbugs.gnu.org; 15 Dec 2022 16:07:56 +0000 Original-Received: from localhost ([127.0.0.1]:43508 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p5qm4-00085w-5u for submit@debbugs.gnu.org; Thu, 15 Dec 2022 11:07:56 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:46188) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p5qlz-00085g-RD for 59986@debbugs.gnu.org; Thu, 15 Dec 2022 11:07:54 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5qlu-0000HX-3a; Thu, 15 Dec 2022 11:07:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=TH6iL7NXYsA2k7M+CvlHUhNlMV4rpf5caJLzr8CF1Dk=; b=eE9gDEEZ41Oj GNcCwWhZWnigLKKZe+tZZSLkWvHnGu/Ef9jNt1uTa3iEPpyMZ2mXmWAySrYzAVK3Rjm4DMz9Eo+rO TQ/i+q204Y0U5Z+ISPMFuX/tZTrhGQ5ax2TjxtxL5IjoB0cAqRQH92X48JtU/zeajudfxXsqLFuoq asMGgLX+T9tnnExys4QJhERGnJut4W3OMOUqUo5fykZRQGXT76Pa/v3RnDoL+0TDG0BZlEfT9SBqW S+8Ryt7mPz9IeclzwAbsPHBYkufjGI/5GUaKWSHFZjVu90tXOqd0xSoVdvvpQYC39gKYzGYVRt1Do AsB5vv/7y4b7bNeBVnVTNQ==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5qlt-0000Be-E6; Thu, 15 Dec 2022 11:07:45 -0500 In-Reply-To: (message from Jean Louis on Thu, 15 Dec 2022 17:54:32 +0300) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:251115 Archived-At: > Date: Thu, 15 Dec 2022 17:54:32 +0300 > From: Jean Louis > Cc: Michael Heerdegen , bugs@gnu.support, > 59986@debbugs.gnu.org > > If there is dangling symlink in Trash then even if the file to be > deleted to Trash exists and is not symlink, I get the same error > message: Can you try the patch below and see if it solves the problem? diff --git a/lisp/files.el b/lisp/files.el index d785d4f..c74e7e8 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -8467,6 +8467,14 @@ 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 @@ -8497,7 +8505,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-p new-fn) + (if (file-exists-in-trash-p new-fn) (let ((version-control t) (backup-directory-alist nil)) (setq new-fn (car (find-backup-file-name new-fn))))) @@ -8574,7 +8582,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-p + (when (file-exists-in-trash-p (file-name-concat trash-files-dir files-base)) (setq overwrite t files-base (file-name-nondirectory @@ -8612,7 +8620,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-p new-fn))) + (not (file-exists-in-trash-p new-fn))) (rename-file fn new-fn overwrite) (copy-directory fn (file-name-as-directory new-fn)