unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: emacs-pretest-bug@gnu.org
Subject: bug#5225: dired-diff should be more safe
Date: Wed, 16 Dec 2009 11:19:09 +0200	[thread overview]
Message-ID: <87vdg7cm42.fsf@mail.jurta.org> (raw)

Currently using `dired-diff' has a high risk of deleting a file.

When two compared file names refer to the same file, or when one of them
is the directory name of the second file (thus the file is compared
against itself), then the user may not notice that `diff' compares the
same file with itself, and when `diff' says there are no differences,
decide to delete the file (thinking that two files have the same content).

The patch below eliminates this risk by signalling an error when
comparing the same file to itself:

=== modified file 'lisp/dired-aux.el'
--- lisp/dired-aux.el	2009-11-25 17:15:19 +0000
+++ lisp/dired-aux.el	2009-12-16 09:16:34 +0000
@@ -60,27 +60,44 @@
 		       (if (stringp diff-switches)
 			   diff-switches
 			 (mapconcat 'identity diff-switches " ")))))))
-  (diff file (dired-get-filename t) switches))
+  (let ((current (dired-get-filename t)))
+    (when (or (equal (expand-file-name file)
+		     (expand-file-name current))
+	      (and (file-directory-p file)
+		   (equal (expand-file-name current file)
+			  (expand-file-name current))))
+      (error "Attempt to compare the file to itself"))
+    (diff file current switches)))
 
 ;;;###autoload
 (defun dired-backup-diff (&optional switches)

-- 
Juri Linkov
http://www.jurta.org/emacs/





                 reply	other threads:[~2009-12-16  9:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=87vdg7cm42.fsf@mail.jurta.org \
    --to=juri@jurta.org \
    --cc=5225@emacsbugs.donarmstrong.com \
    --cc=emacs-pretest-bug@gnu.org \
    /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).