unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] fix first `save-buffer' with `break-hardlink-on-save' set
@ 2011-05-15 15:48 Nix
  2011-05-20  0:51 ` Glenn Morris
  0 siblings, 1 reply; 2+ messages in thread
From: Nix @ 2011-05-15 15:48 UTC (permalink / raw)
  To: emacs-devel

Currently, on bzr head, if `break-hardlink-on-save' is set, you can only
overwrite existing files: you cannot write new ones: attempts to write
new ones throws a Lisp error. This is because `basic-save-2' calls
`file-nlinks' without consideration of whether the file exists already,
and (> nil 1) is an error.

Fix below. (I'm not sure if, in the Bazaar world, you prefer to have
ChangeLogs incorporated in the diff itself. I'm sticking to pre-Bazaar
conventions for now.)

2011-05-15  Nix  <nix@esperi.org.uk>

	* files.el (basic-save-buffer-2): Only check `file-nlinks' and
	directory writability if the file already exists.

Index: emacs/lisp/files.el
===================================================================
--- emacs.orig/lisp/files.el	2011-05-15 16:36:56.187046000 +0100
+++ emacs/lisp/files.el	2011-05-15 16:41:26.832058984 +0100
@@ -4516,12 +4516,13 @@
     (let* ((dir (file-name-directory buffer-file-name))
            (dir-writable (file-writable-p dir)))
       (if (or (and file-precious-flag dir-writable)
-              (and break-hardlink-on-save
-                   (> (file-nlinks buffer-file-name) 1)
-                   (or dir-writable
-                       (error (concat (format
-                                       "Directory %s write-protected; " dir)
-                                      "cannot break hardlink when saving")))))
+	      (and break-hardlink-on-save
+		   (file-exists-p buffer-file-name)
+		   (> (file-nlinks buffer-file-name) 1)
+		   (or dir-writable
+		       (error (concat (format
+				       "Directory %s write-protected; " dir)
+				      "cannot break hardlink when saving")))))
 	  ;; Write temp name, then rename it.
 	  ;; This requires write access to the containing dir,
 	  ;; which is why we don't try it if we don't have that access.




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] fix first `save-buffer' with `break-hardlink-on-save' set
  2011-05-15 15:48 [PATCH] fix first `save-buffer' with `break-hardlink-on-save' set Nix
@ 2011-05-20  0:51 ` Glenn Morris
  0 siblings, 0 replies; 2+ messages in thread
From: Glenn Morris @ 2011-05-20  0:51 UTC (permalink / raw)
  To: Nix; +Cc: emacs-devel


Thanks; applied.

It is better to send patches and bug reports to the bug list, BTW.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-05-20  0:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-15 15:48 [PATCH] fix first `save-buffer' with `break-hardlink-on-save' set Nix
2011-05-20  0:51 ` Glenn Morris

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).