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)
This commit is contained in:
Eli Zaretskii 2017-12-01 12:40:26 +02:00
parent 8eb6870be6
commit 8c8b673288

View file

@ -4653,25 +4653,41 @@ The function `find-backup-file-name' also uses this."
;; "/drive_x". ;; "/drive_x".
(or (file-name-absolute-p file) (or (file-name-absolute-p file)
(setq file (expand-file-name file))) ; make defaults explicit (setq file (expand-file-name file))) ; make defaults explicit
;; Replace any invalid file-name characters (for the (cond
;; case of backing up remote files). ((file-remote-p file)
(setq file (expand-file-name (convert-standard-filename file))) ;; Remove the leading slash, if any, to prevent
(if (eq (aref file 1) ?:) ;; expand-file-name from adding a drive letter.
(setq file (concat "/" (and (memq (aref file 0) '(?/ ?\\))
"drive_" (setq file (substring file 1)))
(char-to-string (downcase (aref file 0))) ;; Replace any invalid file-name characters.
(if (eq (aref file 2) ?/) (setq file (convert-standard-filename file))
"" ;; Replace slashes to make the file name unique, and
"/") ;; prepend backup-directory.
(substring file 2))))) (expand-file-name
;; Make the name unique by substituting directory (subst-char-in-string
;; separators. It may not really be worth bothering about ?/ ?!
;; doubling `!'s in the original name... (replace-regexp-in-string "!" "!!"
(expand-file-name (concat "/" file)))
(subst-char-in-string backup-directory))
?/ ?! (t
(replace-regexp-in-string "!" "!!" file)) ;; Replace any invalid file-name characters.
backup-directory)) (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) (expand-file-name (file-name-nondirectory file)
(file-name-as-directory abs-backup-directory)))))) (file-name-as-directory abs-backup-directory))))))