aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorPaul Eggert2017-08-12 20:04:43 -0700
committerPaul Eggert2017-08-12 20:05:23 -0700
commitebf53ed4f6469d24c3a76835eab014d82aed551c (patch)
tree6a5f10abdc9c59f02910cde7e5f4e479d4835d1d /lisp
parenta6ad98ad66e1d0c0dac5f25ba91e11d0cf9da725 (diff)
downloademacs-ebf53ed4f6469d24c3a76835eab014d82aed551c.tar.gz
emacs-ebf53ed4f6469d24c3a76835eab014d82aed551c.zip
Fix make-temp-file bug with ""/"."/".." prefix
The bug with "." and ".." has been present for a while; I introduced the bug with "" earlier today in my patch for Bug#28023. * lisp/files.el (make-temp-file): Do not use expand-file-name if PREFIX is empty or "." or "..", as it does the wrong thing. Compute absolute-prefix here ... (files--make-magic-temp-file): ... instead of here ... * src/fileio.c (Fmake_temp_file_internal): ... or here. * lisp/files.el (make-temp-file): If the prefix is empty, append "/" to the absolute prefix so that the new files are children rather than siblings of temporary-file-directory. This fixes a bug introduced in the previous change. * test/lisp/files-tests.el (files-test-make-temp-file-empty-prefix): New test, for the bug.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/files.el19
1 files changed, 8 insertions, 11 deletions
diff --git a/lisp/files.el b/lisp/files.el
index 19573cdf7b2..b05d453b0e7 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1407,14 +1407,17 @@ You can then use `write-region' to write new data into the file.
1407If DIR-FLAG is non-nil, create a new empty directory instead of a file. 1407If DIR-FLAG is non-nil, create a new empty directory instead of a file.
1408 1408
1409If SUFFIX is non-nil, add that at the end of the file name." 1409If SUFFIX is non-nil, add that at the end of the file name."
1410 (let ((absolute-prefix (expand-file-name prefix temporary-file-directory))) 1410 (let ((absolute-prefix
1411 (if (or (zerop (length prefix)) (member prefix '("." "..")))
1412 (concat (file-name-as-directory temporary-file-directory) prefix)
1413 (expand-file-name prefix temporary-file-directory))))
1411 (if (find-file-name-handler absolute-prefix 'write-region) 1414 (if (find-file-name-handler absolute-prefix 'write-region)
1412 (files--make-magic-temp-file prefix dir-flag suffix) 1415 (files--make-magic-temp-file absolute-prefix dir-flag suffix)
1413 (make-temp-file-internal absolute-prefix 1416 (make-temp-file-internal absolute-prefix
1414 (if dir-flag t) (or suffix ""))))) 1417 (if dir-flag t) (or suffix "")))))
1415 1418
1416(defun files--make-magic-temp-file (prefix &optional dir-flag suffix) 1419(defun files--make-magic-temp-file (absolute-prefix &optional dir-flag suffix)
1417 "Implement (make-temp-file PREFIX DIR-FLAG SUFFIX). 1420 "Implement (make-temp-file ABSOLUTE-PREFIX DIR-FLAG SUFFIX).
1418This implementation works on magic file names." 1421This implementation works on magic file names."
1419 ;; Create temp files with strict access rights. It's easy to 1422 ;; Create temp files with strict access rights. It's easy to
1420 ;; loosen them later, whereas it's impossible to close the 1423 ;; loosen them later, whereas it's impossible to close the
@@ -1423,13 +1426,7 @@ This implementation works on magic file names."
1423 (let (file) 1426 (let (file)
1424 (while (condition-case () 1427 (while (condition-case ()
1425 (progn 1428 (progn
1426 (setq file 1429 (setq file (make-temp-name absolute-prefix))
1427 (make-temp-name
1428 (if (zerop (length prefix))
1429 (file-name-as-directory
1430 temporary-file-directory)
1431 (expand-file-name prefix
1432 temporary-file-directory))))
1433 (if suffix 1430 (if suffix
1434 (setq file (concat file suffix))) 1431 (setq file (concat file suffix)))
1435 (if dir-flag 1432 (if dir-flag