unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#23050: package.el overwrites symlinks when saving "(package-initialize)"
@ 2016-03-18  6:53 Jackson Hamilton
  2016-03-19  2:05 ` Glenn Morris
  2016-05-23  0:40 ` bug#23050: package.el overwrites symlinks when saving "(package-initialize)" Paul Eggert
  0 siblings, 2 replies; 5+ messages in thread
From: Jackson Hamilton @ 2016-03-18  6:53 UTC (permalink / raw)
  To: 23050

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

Emacs version: 25.0.91.1
OS: Debian 8 GNU/Linux

When I create a symlink in my ~/.emacs.d directory to my init.el file at
some other location, and the init file does not have "(package-initialize)"
inside it, then when package.el adds the "(package-initialize)" line to my
init file on startup, instead of updating the original file, it seems to
make a copy of the symlinked file in the ~/.emacs.d directory. This is bad,
because now (probably without my immediate knowledge), I now have two very
similar init files, and editing the supposedly-symlinked one will do
nothing.

I don't really like the idea of my init file being written-to without my
consent in the first place. But anyway, Emacs should at least do me the
courtesy of modifying the symlinked file, because that's clearly the only
copy of the file I want to maintain.

[-- Attachment #2: Type: text/html, Size: 934 bytes --]

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

* bug#23050: package.el overwrites symlinks when saving "(package-initialize)"
  2016-03-18  6:53 bug#23050: package.el overwrites symlinks when saving "(package-initialize)" Jackson Hamilton
@ 2016-03-19  2:05 ` Glenn Morris
  2016-03-19  2:13   ` Glenn Morris
  2016-05-23  0:40 ` bug#23050: package.el overwrites symlinks when saving "(package-initialize)" Paul Eggert
  1 sibling, 1 reply; 5+ messages in thread
From: Glenn Morris @ 2016-03-19  2:05 UTC (permalink / raw)
  To: Jackson Hamilton; +Cc: 23050

Jackson Hamilton wrote:

> When I create a symlink in my ~/.emacs.d directory to my init.el file at
> some other location, and the init file does not have "(package-initialize)"
> inside it, then when package.el adds the "(package-initialize)" line to my
> init file on startup, instead of updating the original file, it seems to
> make a copy of the symlinked file in the ~/.emacs.d directory.

I see the relevant code binds file-precious-flag, so this is
http://debbugs.gnu.org/18125 .





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

* bug#23050: package.el overwrites symlinks when saving "(package-initialize)"
  2016-03-19  2:05 ` Glenn Morris
@ 2016-03-19  2:13   ` Glenn Morris
  2016-03-22 16:51     ` bug#23050: package.el overwrites symlinks when saving Bogolisk
  0 siblings, 1 reply; 5+ messages in thread
From: Glenn Morris @ 2016-03-19  2:13 UTC (permalink / raw)
  To: Jackson Hamilton; +Cc: 23050

Glenn Morris wrote:

> I see the relevant code binds file-precious-flag, so this is
> http://debbugs.gnu.org/18125 .

PS So package.el could avoid the issue by binding
find-file-visit-truename, like cus-edit does (see bug#454).





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

* bug#23050: package.el overwrites symlinks when saving
  2016-03-19  2:13   ` Glenn Morris
@ 2016-03-22 16:51     ` Bogolisk
  0 siblings, 0 replies; 5+ messages in thread
From: Bogolisk @ 2016-03-22 16:51 UTC (permalink / raw)
  To: 23050

Glenn Morris <rgm <at> gnu.org> writes:

> 
> Glenn Morris wrote:
> 
> > I see the relevant code binds file-precious-flag, so this is
> > http://debbugs.gnu.org/18125 .
> 
> PS So package.el could avoid the issue by binding
> find-file-visit-truename, like cus-edit does (see bug#454).
> 
> 


The fix is for basic-save-buffer-2() to use buffer-file-truename when save-
by-rename.

--- files.old.el	2016-03-22 12:43:37.124790562 -0400
+++ files.new.el	2016-03-22 12:44:32.361602364 -0400
@@ -4840,29 +4840,29 @@
 ;; backup-buffer.
 (defun basic-save-buffer-2 ()
   (let (tempsetmodes setmodes)
-    (if (not (file-writable-p buffer-file-name))
-	(let ((dir (file-name-directory buffer-file-name)))
+    (if (not (file-writable-p buffer-file-truename))
+	(let ((dir (file-name-directory buffer-file-truename)))
 	  (if (not (file-directory-p dir))
 	      (if (file-exists-p dir)
 		  (error "%s is not a directory" dir)
 		(error "%s: no such directory" dir))
-	    (if (not (file-exists-p buffer-file-name))
+	    (if (not (file-exists-p buffer-file-truename))
 		(error "Directory %s write-protected" dir)
 	      (if (yes-or-no-p
 		   (format
 		    "File %s is write-protected; try to save anyway? "
 		    (file-name-nondirectory
-		     buffer-file-name)))
+		     buffer-file-truename)))
 		  (setq tempsetmodes t)
 		(error "Attempt to save to a file which you aren't allowed 
to write"))))))
     (or buffer-backed-up
 	(setq setmodes (backup-buffer)))
-    (let* ((dir (file-name-directory buffer-file-name))
+    (let* ((dir (file-name-directory buffer-file-truename))
            (dir-writable (file-writable-p dir)))
       (if (or (and file-precious-flag dir-writable)
               (and break-hardlink-on-save
-                   (file-exists-p buffer-file-name)
-                   (> (file-nlinks buffer-file-name) 1)
+                   (file-exists-p buffer-file-truename)
+                   (> (file-nlinks buffer-file-truename) 1)
                    (or dir-writable
                        (error (concat "Directory %s write-protected; "
                                       "cannot break hardlink when saving")
@@ -4870,7 +4870,7 @@
 	  ;; 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.
-	  (let ((realname buffer-file-name)
+	  (let ((realname buffer-file-truename)
 		tempname succeed
 		(umask (default-file-modes))
 		(old-modtime (visited-file-modtime)))
@@ -4911,13 +4911,13 @@
 	    ;; Since we have created an entirely new file,
 	    ;; make sure it gets the right permission bits set.
 	    (setq setmodes (or setmodes
- 			       (list (or (file-modes buffer-file-name)
+ 			       (list (or (file-modes buffer-file-truename)
 					 (logand ?\666 umask))
-				     (file-extended-attributes buffer-file-
name)
-				     buffer-file-name)))
+				     (file-extended-attributes buffer-file-
truename)
+				     buffer-file-truename)))
 	    ;; We succeeded in writing the temp file,
 	    ;; so rename it.
-	    (rename-file tempname buffer-file-name t))
+	    (rename-file tempname buffer-file-truename t))
 	;; If file not writable, see if we can make it writable
 	;; temporarily while we write it.
 	;; But no need to do so if we have just backed it up







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

* bug#23050: package.el overwrites symlinks when saving "(package-initialize)"
  2016-03-18  6:53 bug#23050: package.el overwrites symlinks when saving "(package-initialize)" Jackson Hamilton
  2016-03-19  2:05 ` Glenn Morris
@ 2016-05-23  0:40 ` Paul Eggert
  1 sibling, 0 replies; 5+ messages in thread
From: Paul Eggert @ 2016-05-23  0:40 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 23050-done, Bogolisk, Jackson Hamilton

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

> So package.el could avoid the issue by binding
> find-file-visit-truename, like cus-edit does (see bug#454).

Thanks, that suggestion worked when I tried it, so I installed the attached 
patch into emacs-25 and am marking this bug as done.

[-- Attachment #2: 0001-Do-not-trash-symlinks-to-init-file.txt --]
[-- Type: text/plain, Size: 2395 bytes --]

From 239521765c6ecf5679463dd9603359bf907570eb Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sun, 22 May 2016 17:29:58 -0700
Subject: [PATCH] Do not trash symlinks to init file
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

If the user’s init file is a symbolic link, do not break the link
when initializing the package system.  Problem reported by Jackson
Hamilton (Bug#23050).
* lisp/emacs-lisp/package.el (package--ensure-init-file):
Bind find-file-visit-truename when visiting the init file, and
save and restore the buffer name the way cus-edit does in a
similar situation (Bug#454).
---
 lisp/emacs-lisp/package.el | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index b0a6db0..14626e2 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -1869,6 +1869,7 @@ package--ensure-init-file
              (file-readable-p user-init-file)
              (file-writable-p user-init-file))
     (let* ((buffer (find-buffer-visiting user-init-file))
+           buffer-name
            (contains-init
             (if buffer
                 (with-current-buffer buffer
@@ -1884,8 +1885,12 @@ package--ensure-init-file
                 (re-search-forward "(package-initialize\\_>" nil 'noerror)))))
       (unless contains-init
         (with-current-buffer (or buffer
-                                 (let ((delay-mode-hooks t))
+                                 (let ((delay-mode-hooks t)
+                                       (find-file-visit-truename t))
                                    (find-file-noselect user-init-file)))
+          (when buffer
+            (setq buffer-name (buffer-file-name))
+            (set-visited-file-name (file-chase-links user-init-file)))
           (save-excursion
             (save-restriction
               (widen)
@@ -1904,7 +1909,10 @@ package--ensure-init-file
                 (insert "\n"))
               (let ((file-precious-flag t))
                 (save-buffer))
-              (unless buffer
+              (if buffer
+                  (progn
+                    (set-visited-file-name buffer-name)
+                    (set-buffer-modified-p nil))
                 (kill-buffer (current-buffer)))))))))
   (setq package--init-file-ensured t))
 
-- 
2.7.4


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

end of thread, other threads:[~2016-05-23  0:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-18  6:53 bug#23050: package.el overwrites symlinks when saving "(package-initialize)" Jackson Hamilton
2016-03-19  2:05 ` Glenn Morris
2016-03-19  2:13   ` Glenn Morris
2016-03-22 16:51     ` bug#23050: package.el overwrites symlinks when saving Bogolisk
2016-05-23  0:40 ` bug#23050: package.el overwrites symlinks when saving "(package-initialize)" Paul Eggert

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