emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs-26 66ec92a: Fix backing up remote files in local dir


From: Eli Zaretskii
Subject: [Emacs-diffs] emacs-26 66ec92a: Fix backing up remote files in local directories on MS-Windows
Date: Sat, 2 Dec 2017 03:58:06 -0500 (EST)

branch: emacs-26
commit 66ec92af0060952ef7b53a8f1c07177cf38b3145
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Fix backing up remote files in local directories on MS-Windows
    
    * lisp/files.el (make-backup-file-name-1): Support remote file
    names correctly when they are backed up into a local directory on
    MS-Windows and MS-DOS.  (Bug#29440)
---
 lisp/files.el | 48 +++++++++++++++++++++++++++++-------------------
 1 file changed, 29 insertions(+), 19 deletions(-)

diff --git a/lisp/files.el b/lisp/files.el
index 8021e1b..1bdb6d3 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -4653,25 +4653,35 @@ The function `find-backup-file-name' also uses this."
              ;; "/drive_x".
              (or (file-name-absolute-p file)
                  (setq file (expand-file-name file))) ; make defaults explicit
-             ;; Replace any invalid file-name characters (for the
-             ;; case of backing up remote files).
-             (setq file (expand-file-name (convert-standard-filename file)))
-             (if (eq (aref file 1) ?:)
-                 (setq file (concat "/"
-                                    "drive_"
-                                    (char-to-string (downcase (aref file 0)))
-                                    (if (eq (aref file 2) ?/)
-                                        ""
-                                      "/")
-                                    (substring file 2)))))
-           ;; Make the name unique by substituting directory
-           ;; separators.  It may not really be worth bothering about
-           ;; doubling `!'s in the original name...
-           (expand-file-name
-            (subst-char-in-string
-             ?/ ?!
-             (replace-regexp-in-string "!" "!!" file))
-            backup-directory))
+              (cond
+               ((file-remote-p file)
+                ;; Remove the leading slash, if any, to prevent
+                ;; convert-standard-filename from converting that to a
+                ;; backslash.
+                (and (memq (aref file 0) '(?/ ?\\))
+                     (setq file (substring file 1)))
+               ;; Replace any invalid file-name characters, then
+               ;; prepend the leading slash back.
+                (setq file (concat "/" (convert-standard-filename file))))
+               (t
+               ;; Replace any invalid file-name characters.
+               (setq file (expand-file-name (convert-standard-filename file)))
+               (if (eq (aref file 1) ?:)
+                   (setq file (concat "/"
+                                      "drive_"
+                                      (char-to-string (downcase (aref file 0)))
+                                      (if (eq (aref file 2) ?/)
+                                          ""
+                                        "/")
+                                      (substring file 2))))))
+             ;; Make the name unique by substituting directory
+             ;; separators.  It may not really be worth bothering about
+             ;; doubling `!'s in the original name...
+             (expand-file-name
+              (subst-char-in-string
+               ?/ ?!
+               (replace-regexp-in-string "!" "!!" file))
+              backup-directory)))
        (expand-file-name (file-name-nondirectory file)
                          (file-name-as-directory abs-backup-directory))))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]