summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2002-03-06 18:19:43 +0000
committerEli Zaretskii <eliz@gnu.org>2002-03-06 18:19:43 +0000
commit1e57a69675b0597c3ad381dc19d514d3b54e28c5 (patch)
treebdc38b99d6c633c28ff224d5466cd45708ca460c /lisp
parent6b3daede302af9fcb6a40a0aad29810b991fb4a5 (diff)
downloademacs-1e57a69675b0597c3ad381dc19d514d3b54e28c5.tar.gz
emacs-1e57a69675b0597c3ad381dc19d514d3b54e28c5.tar.bz2
emacs-1e57a69675b0597c3ad381dc19d514d3b54e28c5.zip
(make-auto-save-file-name): Make sure the produced file
name does not contain characters that are invalid for DOS/Windows filesystems.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/files.el69
1 files changed, 46 insertions, 23 deletions
diff --git a/lisp/files.el b/lisp/files.el
index f5ab220ba15..f02ce05cef2 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -3308,22 +3308,33 @@ See also `auto-save-file-name-p'."
(setq list (cdr list)))
(if result (setq filename result))
- (if (and (eq system-type 'ms-dos)
- (not (msdos-long-file-names)))
- ;; We truncate the file name to DOS 8+3 limits before
- ;; doing anything else, because the regexp passed to
- ;; string-match below cannot handle extensions longer than
- ;; 3 characters, multiple dots, and other atrocities.
- (let ((fn (dos-8+3-filename
- (file-name-nondirectory buffer-file-name))))
- (string-match "\\`\\([^.]+\\)\\(\\.\\(..?\\)?.?\\|\\)\\'" fn)
- (concat (file-name-directory buffer-file-name)
- "#" (match-string 1 fn)
- "." (match-string 3 fn) "#"))
- (concat (file-name-directory filename)
- "#"
- (file-name-nondirectory filename)
- "#")))
+ (setq result
+ (if (and (eq system-type 'ms-dos)
+ (not (msdos-long-file-names)))
+ ;; We truncate the file name to DOS 8+3 limits
+ ;; before doing anything else, because the regexp
+ ;; passed to string-match below cannot handle
+ ;; extensions longer than 3 characters, multiple
+ ;; dots, and other atrocities.
+ (let ((fn (dos-8+3-filename
+ (file-name-nondirectory buffer-file-name))))
+ (string-match
+ "\\`\\([^.]+\\)\\(\\.\\(..?\\)?.?\\|\\)\\'"
+ fn)
+ (concat (file-name-directory buffer-file-name)
+ "#" (match-string 1 fn)
+ "." (match-string 3 fn) "#"))
+ (concat (file-name-directory filename)
+ "#"
+ (file-name-nondirectory filename)
+ "#")))
+ ;; Make sure auto-save file names don't contain characters
+ ;; invalid for the underlying filesystem.
+ (if (and (memq system-type '(ms-dos windows-nt))
+ ;; Don't modify remote (ange-ftp) filenames
+ (not (string-match "^/\\w+@[-A-Za-z0-9._]+:" result)))
+ (convert-standard-filename result)
+ result))
;; Deal with buffers that don't have any associated files. (Mail
;; mode tends to create a good number of these.)
@@ -3343,13 +3354,25 @@ See also `auto-save-file-name-p'."
(setq limit (1+ (match-end 0)))))
;; Generate the file name.
(make-temp-file
- (expand-file-name
- (format "#%s#" buffer-name)
- ;; Try a few alternative directories, to get one we can write it.
- (cond
- ((file-writable-p default-directory) default-directory)
- ((file-writable-p "/var/tmp/") "/var/tmp/")
- ("~/")))))))
+ (let ((fname
+ (expand-file-name
+ (format "#%s#" buffer-name)
+ ;; Try a few alternative directories, to get one we can
+ ;; write it.
+ (cond
+ ((file-writable-p default-directory) default-directory)
+ ((file-writable-p "/var/tmp/") "/var/tmp/")
+ ("~/")))))
+ (if (and (memq system-type '(ms-dos windows-nt))
+ ;; Don't modify remote (ange-ftp) filenames
+ (not (string-match "^/\\w+@[-A-Za-z0-9._]+:" fname)))
+ ;; The call to convert-standard-filename is in case
+ ;; buffer-name includes characters not allowed by the
+ ;; DOS/Windows filesystems. make-temp-file writes to the
+ ;; file it creates, so we must fix the file name _before_
+ ;; make-temp-file is called.
+ (convert-standard-filename fname)
+ fname))))))
(defun auto-save-file-name-p (filename)
"Return non-nil if FILENAME can be yielded by `make-auto-save-file-name'.