aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2016-08-07 13:57:23 +0200
committerMichael Albinus2016-08-07 13:57:23 +0200
commit2c0506173d92dd9d6de409a045668c6b5cf1fcef (patch)
tree2ea1931603ecabe4b544600029b52215cc75f7f7
parenta798547727081de5b99e1036783084fcb9afec75 (diff)
downloademacs-2c0506173d92dd9d6de409a045668c6b5cf1fcef.tar.gz
emacs-2c0506173d92dd9d6de409a045668c6b5cf1fcef.zip
Add `make-nearby-temp-file' and `temporary-file-directory'
* doc/lispref/files.texi (Unique File Names): Introduce `make-nearby-temp-file' and `temporary-file-directory'. (Magic File Names): Mention `make-nearby-temp-file' and `temporary-file-directory'. * etc/NEWS (provided): Mention `make-nearby-temp-file' and `temporary-file-directory'. * lisp/files.el (mounted-file-systems): New defcustom. (temporary-file-directory, make-nearby-temp-file): New defuns. (normal-backup-enable-predicate): Fix docstring. * lisp/net/tramp-adb.el (tramp-adb-file-name-handler-alist): * lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-handler-alist): * lisp/net/tramp-sh.el (tramp-sh-file-name-handler-alist): * lisp/net/tramp-smb.el (tramp-smb-file-name-handler-alist): <make-nearby-temp-file, temporary-file-directory>: Add handler. * lisp/net/tramp.el (tramp-file-name-for-operation): Add `make-nearby-temp-file' and `temporary-file-directory'. (tramp-get-remote-tmpdir): Remove compatibility code. (tramp-handle-temporary-file-directory) (tramp-handle-make-nearby-temp-file): New defuns. * lisp/org/ob-core.el (org-babel-local-file-name): * lisp/progmodes/gud.el (gud-common-init): * lisp/vc/vc-hooks.el (vc-user-login-name): Use `file-remote-p'. * lisp/vc/vc-git.el (vc-git-checkin): Handle remote log message. * test/lisp/net/tramp-tests.el (tramp-test06-directory-file-name): Check `tramp--test-enabled'. (tramp-test18-file-attributes): Add tests for `file-ownership-preserved-p'. (tramp-test27-start-file-process, tramp-test28-shell-command): Reduce timeouts in `accept-process-output'. (tramp-test--shell-command-to-string-asynchronously): Add timeout. (tramp-test29-environment-variables): Remove additional sleep calls. (tramp-test32-make-nearby-temp-file): New test. (tramp--test-special-characters, tramp--test-utf8): Adapt docstring. (tramp-test33-special-characters) (tramp-test33-special-characters-with-stat) (tramp-test33-special-characters-with-perl) (tramp-test33-special-characters-with-ls, tramp-test34-utf8) (tramp-test34-utf8-with-stat, tramp-test34-utf8-with-perl) (tramp-test34-utf8-with-ls) (tramp-test35-asynchronous-requests) (tramp-test36-recursive-load, tramp-test37-unload): Rename. (tramp--test-ftp-p): Simplify check. (tramp--test-sh-p): New defun. (tramp-test20-file-modes, tramp-test22-file-times) (tramp-test26-process-file, tramp-test27-start-file-process) (tramp-test28-shell-command) (tramp-test29-environment-variables) (tramp-test30-vc-registered) (tramp-test33-special-characters-with-stat) (tramp-test33-special-characters-with-perl) (tramp-test33-special-characters-with-ls) (tramp-test34-utf8-with-stat, tramp-test34-utf8-with-perl) (tramp-test34-utf8-with-ls) (tramp-test35-asynchronous-requests): Use it.
-rw-r--r--doc/lispref/files.texi46
-rw-r--r--etc/NEWS6
-rw-r--r--lisp/files.el47
-rw-r--r--lisp/net/tramp-adb.el2
-rw-r--r--lisp/net/tramp-gvfs.el2
-rw-r--r--lisp/net/tramp-sh.el2
-rw-r--r--lisp/net/tramp-smb.el2
-rw-r--r--lisp/net/tramp.el22
-rw-r--r--lisp/org/ob-core.el13
-rw-r--r--lisp/progmodes/gud.el6
-rw-r--r--lisp/vc/vc-git.el7
-rw-r--r--lisp/vc/vc-hooks.el2
-rw-r--r--test/lisp/net/tramp-tests.el241
13 files changed, 249 insertions, 149 deletions
diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi
index ea9d53b0ea6..0aea1dfd9a3 100644
--- a/doc/lispref/files.texi
+++ b/doc/lispref/files.texi
@@ -2440,6 +2440,50 @@ condition, between the @code{make-temp-name} call and the creation of
2440the file, which in some cases may cause a security hole. 2440the file, which in some cases may cause a security hole.
2441@end defun 2441@end defun
2442 2442
2443Sometimes, it is necessary to create a temporary file on a remote host
2444or a mounted directory. The following two functions support this.
2445
2446@defun make-nearby-temp-file prefix &optional dir-flag suffix
2447This function is similar to @code{make-temp-file}, but it creates a
2448temporary file as close as possible to @code{default-directory}. If
2449@var{prefix} is a relative file name, and @code{default-directory} is
2450a remote file name or located on a mounted file systems, the temporary
2451file is created in the directory returned by the function
2452@code{temporary-file-directory}. Otherwise, the function
2453@code{make-temp-file} is used. @var{prefix}, @var{dir-flag} and
2454@var{suffix} have the same meaning as in @code{make-temp-file}.
2455
2456@example
2457@group
2458(let ((default-directory "/ssh:remotehost:"))
2459 (make-nearby-temp-file "foo"))
2460 @result{} "/ssh:remotehost:/tmp/foo232J6v"
2461@end group
2462@end example
2463@end defun
2464
2465@defun temporary-file-directory
2466The directory for writing temporary files via
2467@code{make-nearby-temp-file}. In case of a remote
2468@code{default-directory}, this is a directory for temporary files on
2469that remote host. If such a directory does not exist, or
2470@code{default-directory} ought to be located on a mounted file system
2471(see @code{mounted-file-systems}), the function returns
2472@code{default-directory}. For a non-remote and non-mounted
2473@code{default-directory}, the value of the variable
2474@code{temporary-file-directory} is returned.
2475@end defun
2476
2477In order to extract the local part of the path name from a temporary
2478file, the following code could be used:
2479
2480@example
2481@group
2482(let ((tmpfile (make-nearby-temp-file "foo")))
2483 (or (file-remote-p tmpfile 'localname) tmpfile))
2484@end group
2485@end example
2486
2443@node File Name Completion 2487@node File Name Completion
2444@subsection File Name Completion 2488@subsection File Name Completion
2445@cindex file name completion subroutines 2489@cindex file name completion subroutines
@@ -2903,6 +2947,7 @@ first, before handlers for jobs such as remote file access.
2903@code{make-auto-save-file-name}, 2947@code{make-auto-save-file-name},
2904@code{make-directory}, 2948@code{make-directory},
2905@code{make-directory-internal}, 2949@code{make-directory-internal},
2950@code{make-nearby-temp-file},
2906@code{make-symbolic-link},@* 2951@code{make-symbolic-link},@*
2907@code{process-file}, 2952@code{process-file},
2908@code{rename-file}, @code{set-file-acl}, @code{set-file-modes}, 2953@code{rename-file}, @code{set-file-acl}, @code{set-file-modes},
@@ -2910,6 +2955,7 @@ first, before handlers for jobs such as remote file access.
2910@code{set-visited-file-modtime}, @code{shell-command}, 2955@code{set-visited-file-modtime}, @code{shell-command},
2911@code{start-file-process}, 2956@code{start-file-process},
2912@code{substitute-in-file-name},@* 2957@code{substitute-in-file-name},@*
2958@code{temporary-file-directory},
2913@code{unhandled-file-name-directory}, 2959@code{unhandled-file-name-directory},
2914@code{vc-registered}, 2960@code{vc-registered},
2915@code{verify-visited-file-modtime},@* 2961@code{verify-visited-file-modtime},@*
diff --git a/etc/NEWS b/etc/NEWS
index 04c293dfc7c..0a202ccade2 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -563,7 +563,11 @@ ABBR is a time zone abbreviation. The affected functions are
563The Info-quoted and tex-verbatim faces now default to inheriting from it. 563The Info-quoted and tex-verbatim faces now default to inheriting from it.
564 564
565** New built-in function `mapcan' which avoids unnecessary consing (and garbage 565** New built-in function `mapcan' which avoids unnecessary consing (and garbage
566 collection). 566collection).
567
568+++
569** The new functions `make-nearby-temp-file' and `temporary-file-directory'
570can be used for creation of temporary files of remote or mounted directories.
567 571
568 572
569* Changes in Emacs 25.2 on Non-Free Operating Systems 573* Changes in Emacs 25.2 on Non-Free Operating Systems
diff --git a/lisp/files.el b/lisp/files.el
index 4d27ef16f7d..1d7870be488 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1314,6 +1314,36 @@ Optional second argument FLAVOR controls the units and the display format:
1314 (car post-fixes)) 1314 (car post-fixes))
1315 (if (eq flavor 'iec) "iB" "")))) 1315 (if (eq flavor 'iec) "iB" ""))))
1316 1316
1317(defcustom mounted-file-systems
1318 (if (memq system-type '(windows-nt cygwin))
1319 "^//[^/]+/"
1320 ;; regexp-opt.el is not dumped into emacs binary.
1321 ;;(concat
1322 ;; "^" (regexp-opt '("/afs/" "/media/" "/mnt" "/net/" "/tmp_mnt/"))))
1323 "^\\(?:/\\(?:afs/\\|m\\(?:edia/\\|nt\\)\\|\\(?:ne\\|tmp_mn\\)t/\\)\\)")
1324 "File systems which ought to be mounted."
1325 :group 'files
1326 :version "25.2"
1327 :require 'regexp-opt
1328 :type 'regexp)
1329
1330(defun temporary-file-directory ()
1331 "The directory for writing temporary files.
1332In case of a remote `default-directory', this is a directory for
1333temporary files on that remote host. If such a directory does
1334not exist, or `default-directory' ought to be located on a
1335mounted file system (see `mounted-file-systems'), the function
1336returns `default-directory'.
1337For a non-remote and non-mounted `default-directory', the value of
1338the variable `temporary-file-directory' is returned."
1339 (let ((handler (find-file-name-handler
1340 default-directory 'temporary-file-directory)))
1341 (if handler
1342 (funcall handler 'temporary-file-directory)
1343 (if (string-match mounted-file-systems default-directory)
1344 default-directory
1345 temporary-file-directory))))
1346
1317(defun make-temp-file (prefix &optional dir-flag suffix) 1347(defun make-temp-file (prefix &optional dir-flag suffix)
1318 "Create a temporary file. 1348 "Create a temporary file.
1319The returned file name (created by appending some random characters at the end 1349The returned file name (created by appending some random characters at the end
@@ -1350,6 +1380,21 @@ If SUFFIX is non-nil, add that at the end of the file name."
1350 nil) 1380 nil)
1351 file))) 1381 file)))
1352 1382
1383(defun make-nearby-temp-file (prefix &optional dir-flag suffix)
1384 "Create a temporary file as close as possible to `default-directory'.
1385If PREFIX is a relative file name, and `default-directory' is a
1386remote file name or located on a mounted file systems, the
1387temporary file is created in the directory returned by the
1388function `temporary-file-directory'. Otherwise, the function
1389`make-temp-file' is used. PREFIX, DIR-FLAG and SUFFIX have the
1390same meaning as in `make-temp-file'."
1391 (let ((handler (find-file-name-handler
1392 default-directory 'make-nearby-temp-file)))
1393 (if (and handler (not (file-name-absolute-p default-directory)))
1394 (funcall handler 'make-nearby-temp-file prefix dir-flag suffix)
1395 (let ((temporary-file-directory (temporary-file-directory)))
1396 (make-temp-file prefix dir-flag suffix)))))
1397
1353(defun recode-file-name (file coding new-coding &optional ok-if-already-exists) 1398(defun recode-file-name (file coding new-coding &optional ok-if-already-exists)
1354 "Change the encoding of FILE's name from CODING to NEW-CODING. 1399 "Change the encoding of FILE's name from CODING to NEW-CODING.
1355The value is a new name of FILE. 1400The value is a new name of FILE.
@@ -4404,7 +4449,7 @@ ignored."
4404(defun normal-backup-enable-predicate (name) 4449(defun normal-backup-enable-predicate (name)
4405 "Default `backup-enable-predicate' function. 4450 "Default `backup-enable-predicate' function.
4406Checks for files in `temporary-file-directory', 4451Checks for files in `temporary-file-directory',
4407`small-temporary-file-directory', and /tmp." 4452`small-temporary-file-directory', and \"/tmp\"."
4408 (let ((temporary-file-directory temporary-file-directory) 4453 (let ((temporary-file-directory temporary-file-directory)
4409 caseless) 4454 caseless)
4410 ;; On MS-Windows, file-truename will convert short 8+3 aliases to 4455 ;; On MS-Windows, file-truename will convert short 8+3 aliases to
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index 002a7fe52c1..07fc3e2bf55 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -148,6 +148,7 @@ It is used for TCP/IP devices."
148 (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) 148 (make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
149 (make-directory . tramp-adb-handle-make-directory) 149 (make-directory . tramp-adb-handle-make-directory)
150 (make-directory-internal . ignore) 150 (make-directory-internal . ignore)
151 (make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
151 (make-symbolic-link . tramp-handle-make-symbolic-link) 152 (make-symbolic-link . tramp-handle-make-symbolic-link)
152 (process-file . tramp-adb-handle-process-file) 153 (process-file . tramp-adb-handle-process-file)
153 (rename-file . tramp-adb-handle-rename-file) 154 (rename-file . tramp-adb-handle-rename-file)
@@ -159,6 +160,7 @@ It is used for TCP/IP devices."
159 (shell-command . tramp-adb-handle-shell-command) 160 (shell-command . tramp-adb-handle-shell-command)
160 (start-file-process . tramp-adb-handle-start-file-process) 161 (start-file-process . tramp-adb-handle-start-file-process)
161 (substitute-in-file-name . tramp-handle-substitute-in-file-name) 162 (substitute-in-file-name . tramp-handle-substitute-in-file-name)
163 (temporary-file-directory . tramp-handle-temporary-file-directory)
162 (unhandled-file-name-directory . ignore) 164 (unhandled-file-name-directory . ignore)
163 (vc-registered . ignore) 165 (vc-registered . ignore)
164 (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime) 166 (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime)
diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el
index 62129172d99..d12bab954af 100644
--- a/lisp/net/tramp-gvfs.el
+++ b/lisp/net/tramp-gvfs.el
@@ -502,6 +502,7 @@ Every entry is a list (NAME ADDRESS).")
502 (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) 502 (make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
503 (make-directory . tramp-gvfs-handle-make-directory) 503 (make-directory . tramp-gvfs-handle-make-directory)
504 (make-directory-internal . ignore) 504 (make-directory-internal . ignore)
505 (make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
505 (make-symbolic-link . tramp-handle-make-symbolic-link) 506 (make-symbolic-link . tramp-handle-make-symbolic-link)
506 (process-file . ignore) 507 (process-file . ignore)
507 (rename-file . tramp-gvfs-handle-rename-file) 508 (rename-file . tramp-gvfs-handle-rename-file)
@@ -513,6 +514,7 @@ Every entry is a list (NAME ADDRESS).")
513 (shell-command . ignore) 514 (shell-command . ignore)
514 (start-file-process . ignore) 515 (start-file-process . ignore)
515 (substitute-in-file-name . tramp-handle-substitute-in-file-name) 516 (substitute-in-file-name . tramp-handle-substitute-in-file-name)
517 (temporary-file-directory . tramp-handle-temporary-file-directory)
516 (unhandled-file-name-directory . ignore) 518 (unhandled-file-name-directory . ignore)
517 (vc-registered . ignore) 519 (vc-registered . ignore)
518 (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime) 520 (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime)
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index b41eeac5bb9..f1044730ff0 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -1043,6 +1043,7 @@ of command line.")
1043 (load . tramp-handle-load) 1043 (load . tramp-handle-load)
1044 (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) 1044 (make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
1045 (make-directory . tramp-sh-handle-make-directory) 1045 (make-directory . tramp-sh-handle-make-directory)
1046 (make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
1046 (make-symbolic-link . tramp-sh-handle-make-symbolic-link) 1047 (make-symbolic-link . tramp-sh-handle-make-symbolic-link)
1047 (process-file . tramp-sh-handle-process-file) 1048 (process-file . tramp-sh-handle-process-file)
1048 (rename-file . tramp-sh-handle-rename-file) 1049 (rename-file . tramp-sh-handle-rename-file)
@@ -1054,6 +1055,7 @@ of command line.")
1054 (shell-command . tramp-handle-shell-command) 1055 (shell-command . tramp-handle-shell-command)
1055 (start-file-process . tramp-sh-handle-start-file-process) 1056 (start-file-process . tramp-sh-handle-start-file-process)
1056 (substitute-in-file-name . tramp-handle-substitute-in-file-name) 1057 (substitute-in-file-name . tramp-handle-substitute-in-file-name)
1058 (temporary-file-directory . tramp-handle-temporary-file-directory)
1057 (unhandled-file-name-directory . ignore) 1059 (unhandled-file-name-directory . ignore)
1058 (vc-registered . tramp-sh-handle-vc-registered) 1060 (vc-registered . tramp-sh-handle-vc-registered)
1059 (verify-visited-file-modtime . tramp-sh-handle-verify-visited-file-modtime) 1061 (verify-visited-file-modtime . tramp-sh-handle-verify-visited-file-modtime)
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el
index 60e2aa44c26..bbf88fbf4fc 100644
--- a/lisp/net/tramp-smb.el
+++ b/lisp/net/tramp-smb.el
@@ -265,6 +265,7 @@ See `tramp-actions-before-shell' for more info.")
265 (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) 265 (make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
266 (make-directory . tramp-smb-handle-make-directory) 266 (make-directory . tramp-smb-handle-make-directory)
267 (make-directory-internal . tramp-smb-handle-make-directory-internal) 267 (make-directory-internal . tramp-smb-handle-make-directory-internal)
268 (make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
268 (make-symbolic-link . tramp-smb-handle-make-symbolic-link) 269 (make-symbolic-link . tramp-smb-handle-make-symbolic-link)
269 (process-file . tramp-smb-handle-process-file) 270 (process-file . tramp-smb-handle-process-file)
270 (rename-file . tramp-smb-handle-rename-file) 271 (rename-file . tramp-smb-handle-rename-file)
@@ -276,6 +277,7 @@ See `tramp-actions-before-shell' for more info.")
276 (shell-command . tramp-handle-shell-command) 277 (shell-command . tramp-handle-shell-command)
277 (start-file-process . tramp-smb-handle-start-file-process) 278 (start-file-process . tramp-smb-handle-start-file-process)
278 (substitute-in-file-name . tramp-smb-handle-substitute-in-file-name) 279 (substitute-in-file-name . tramp-smb-handle-substitute-in-file-name)
280 (temporary-file-directory . tramp-handle-temporary-file-directory)
279 (unhandled-file-name-directory . ignore) 281 (unhandled-file-name-directory . ignore)
280 (vc-registered . ignore) 282 (vc-registered . ignore)
281 (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime) 283 (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime)
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 35b049c4f6c..29dd7038c09 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -1917,7 +1917,9 @@ ARGS are the arguments OPERATION has been called with."
1917 (if (bufferp (nth 0 args)) (nth 0 args) (current-buffer)))) 1917 (if (bufferp (nth 0 args)) (nth 0 args) (current-buffer))))
1918 ;; COMMAND. 1918 ;; COMMAND.
1919 ((member operation 1919 ((member operation
1920 '(process-file shell-command start-file-process)) 1920 '(process-file shell-command start-file-process
1921 ;; Emacs 25.2+ only.
1922 make-nearby-temp-file temporary-file-directory))
1921 default-directory) 1923 default-directory)
1922 ;; PROC. 1924 ;; PROC.
1923 ((member operation 1925 ((member operation
@@ -3893,9 +3895,6 @@ be granted."
3893 3895
3894(defun tramp-get-remote-tmpdir (vec) 3896(defun tramp-get-remote-tmpdir (vec)
3895 "Return directory for temporary files on the remote host identified by VEC." 3897 "Return directory for temporary files on the remote host identified by VEC."
3896 (when (file-remote-p (tramp-get-connection-property vec "tmpdir" ""))
3897 ;; Compatibility code: Cached value shall be the local path only.
3898 (tramp-set-connection-property vec "tmpdir" 'undef))
3899 (let ((dir (tramp-make-tramp-file-name 3898 (let ((dir (tramp-make-tramp-file-name
3900 (tramp-file-name-method vec) 3899 (tramp-file-name-method vec)
3901 (tramp-file-name-user vec) 3900 (tramp-file-name-user vec)
@@ -3985,6 +3984,21 @@ ALIST is of the form ((FROM . TO) ...)."
3985 (setq alist (cdr alist)))) 3984 (setq alist (cdr alist))))
3986 string)) 3985 string))
3987 3986
3987(defun tramp-handle-temporary-file-directory ()
3988 "Like `temporary-file-directory' for Tramp files."
3989 (catch 'result
3990 (dolist (dir `(,(ignore-errors
3991 (tramp-get-remote-tmpdir
3992 (tramp-dissect-file-name default-directory)))
3993 ,default-directory))
3994 (when (and (stringp dir) (file-directory-p dir) (file-writable-p dir))
3995 (throw 'result (expand-file-name dir))))))
3996
3997(defun tramp-handle-make-nearby-temp-file (prefix &optional dir-flag suffix)
3998 "Like `make-nearby-temp-file' for Tramp files."
3999 (let ((temporary-file-directory (temporary-file-directory)))
4000 (make-temp-file prefix dir-flag suffix)))
4001
3988;;; Compatibility functions section: 4002;;; Compatibility functions section:
3989 4003
3990(defun tramp-call-process 4004(defun tramp-call-process
diff --git a/lisp/org/ob-core.el b/lisp/org/ob-core.el
index b7e8c237256..e3d778f73b4 100644
--- a/lisp/org/ob-core.el
+++ b/lisp/org/ob-core.el
@@ -43,11 +43,6 @@
43(declare-function org-mark-ring-push "org" (&optional pos buffer)) 43(declare-function org-mark-ring-push "org" (&optional pos buffer))
44(declare-function tramp-compat-make-temp-file "tramp-compat" 44(declare-function tramp-compat-make-temp-file "tramp-compat"
45 (filename &optional dir-flag)) 45 (filename &optional dir-flag))
46(declare-function tramp-dissect-file-name "tramp" (name &optional nodefault))
47(declare-function tramp-file-name-user "tramp" (vec))
48(declare-function tramp-file-name-host "tramp" (vec))
49(declare-function with-parsed-tramp-file-name "tramp" (filename var &rest body)
50 t)
51(declare-function org-icompleting-read "org" (&rest args)) 46(declare-function org-icompleting-read "org" (&rest args))
52(declare-function org-edit-src-code "org-src" 47(declare-function org-edit-src-code "org-src"
53 (&optional context code edit-buffer-name)) 48 (&optional context code edit-buffer-name))
@@ -2670,7 +2665,7 @@ of the string."
2670 (start end program &optional delete buffer display &rest args) 2665 (start end program &optional delete buffer display &rest args)
2671 "Use Tramp to handle `call-process-region'. 2666 "Use Tramp to handle `call-process-region'.
2672Fixes a bug in `tramp-handle-call-process-region'." 2667Fixes a bug in `tramp-handle-call-process-region'."
2673 (if (and (featurep 'tramp) (file-remote-p default-directory)) 2668 (if (file-remote-p default-directory)
2674 (let ((tmpfile (tramp-compat-make-temp-file ""))) 2669 (let ((tmpfile (tramp-compat-make-temp-file "")))
2675 (write-region start end tmpfile) 2670 (write-region start end tmpfile)
2676 (when delete (delete-region start end)) 2671 (when delete (delete-region start end))
@@ -2687,11 +2682,7 @@ Fixes a bug in `tramp-handle-call-process-region'."
2687 2682
2688(defun org-babel-local-file-name (file) 2683(defun org-babel-local-file-name (file)
2689 "Return the local name component of FILE." 2684 "Return the local name component of FILE."
2690 (if (file-remote-p file) 2685 (or (file-remote-p file 'localname) file))
2691 (let (localname)
2692 (with-parsed-tramp-file-name file nil
2693 localname))
2694 file))
2695 2686
2696(defun org-babel-process-file-name (name &optional no-quote-p) 2687(defun org-babel-process-file-name (name &optional no-quote-p)
2697 "Prepare NAME to be used in an external process. 2688 "Prepare NAME to be used in an external process.
diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el
index 504ad546cfd..9052aa40358 100644
--- a/lisp/progmodes/gud.el
+++ b/lisp/progmodes/gud.el
@@ -2567,9 +2567,6 @@ comint mode, which see."
2567 :group 'gud 2567 :group 'gud
2568 :type 'boolean) 2568 :type 'boolean)
2569 2569
2570(declare-function tramp-file-name-localname "tramp" (vec))
2571(declare-function tramp-dissect-file-name "tramp" (name &optional nodefault))
2572
2573;; Perform initializations common to all debuggers. 2570;; Perform initializations common to all debuggers.
2574;; The first arg is the specified command line, 2571;; The first arg is the specified command line,
2575;; which starts with the program to debug. 2572;; which starts with the program to debug.
@@ -2628,8 +2625,7 @@ comint mode, which see."
2628 (setcar w 2625 (setcar w
2629 (if (file-remote-p file) 2626 (if (file-remote-p file)
2630 ;; Tramp has already been loaded if we are here. 2627 ;; Tramp has already been loaded if we are here.
2631 (setq file (tramp-file-name-localname 2628 (setq file (file-remote-p file 'localname))
2632 (tramp-dissect-file-name file)))
2633 file)))) 2629 file))))
2634 (apply 'make-comint (concat "gud" filepart) program nil 2630 (apply 'make-comint (concat "gud" filepart) program nil
2635 (if massage-args (funcall massage-args file args) args)) 2631 (if massage-args (funcall massage-args file args) args))
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index e6fe0196d88..43a831f159f 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -705,7 +705,12 @@ It is based on `log-edit-mode', and has Git-specific extensions.")
705 ;; arguments must be in the system codepage, and therefore 705 ;; arguments must be in the system codepage, and therefore
706 ;; might not support the non-ASCII characters in the log 706 ;; might not support the non-ASCII characters in the log
707 ;; message. 707 ;; message.
708 (if (eq system-type 'windows-nt) (make-temp-file "git-msg")))) 708 (if (eq system-type 'windows-nt)
709 (if (file-remote-p file1)
710 (let ((default-directory (file-name-directory file1)))
711 (file-remote-p
712 (make-nearby-temp-file "git-msg") 'localname))
713 (make-temp-file "git-msg")))))
709 (cl-flet ((boolean-arg-fn 714 (cl-flet ((boolean-arg-fn
710 (argument) 715 (argument)
711 (lambda (value) (when (equal value "yes") (list argument))))) 716 (lambda (value) (when (equal value "yes") (list argument)))))
diff --git a/lisp/vc/vc-hooks.el b/lisp/vc/vc-hooks.el
index 6b4cd6acd03..f59b4632e70 100644
--- a/lisp/vc/vc-hooks.el
+++ b/lisp/vc/vc-hooks.el
@@ -394,7 +394,7 @@ For registered files, the possible values are:
394 394
395(defun vc-user-login-name (file) 395(defun vc-user-login-name (file)
396 "Return the name under which the user accesses the given FILE." 396 "Return the name under which the user accesses the given FILE."
397 (or (and (eq (string-match tramp-file-name-regexp file) 0) 397 (or (and (file-remote-p file)
398 ;; tramp case: execute "whoami" via tramp 398 ;; tramp case: execute "whoami" via tramp
399 (let ((default-directory (file-name-directory file)) 399 (let ((default-directory (file-name-directory file))
400 process-file-side-effects) 400 process-file-side-effects)
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index e05786fa070..af705f6ce67 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -639,23 +639,24 @@ This checks also `file-name-as-directory', `file-name-directory',
639 (unhandled-file-name-directory "/method:host:/path/to/file")) 639 (unhandled-file-name-directory "/method:host:/path/to/file"))
640 640
641 ;; Bug#10085. 641 ;; Bug#10085.
642 (dolist (n-e '(nil t)) 642 (when (tramp--test-enabled) ;; Packages like tramp-gvfs.el might be disabled.
643 ;; We must clear `tramp-default-method'. On hydra, it is "ftp", 643 (dolist (n-e '(nil t))
644 ;; which ruins the tests. 644 ;; We must clear `tramp-default-method'. On hydra, it is "ftp",
645 (let ((non-essential n-e) 645 ;; which ruins the tests.
646 tramp-default-method) 646 (let ((non-essential n-e)
647 (dolist (file 647 tramp-default-method)
648 `(,(file-remote-p tramp-test-temporary-file-directory 'method) 648 (dolist (file
649 ,(file-remote-p tramp-test-temporary-file-directory 'host))) 649 `(,(file-remote-p tramp-test-temporary-file-directory 'method)
650 (unless (zerop (length file)) 650 ,(file-remote-p tramp-test-temporary-file-directory 'host)))
651 (setq file (format "/%s:" file)) 651 (unless (zerop (length file))
652 (should (string-equal (directory-file-name file) file)) 652 (setq file (format "/%s:" file))
653 (should 653 (should (string-equal (directory-file-name file) file))
654 (string-equal 654 (should
655 (file-name-as-directory file) 655 (string-equal
656 (if (tramp-completion-mode-p) file (concat file "./")))) 656 (file-name-as-directory file)
657 (should (string-equal (file-name-directory file) file)) 657 (if (tramp-completion-mode-p) file (concat file "./"))))
658 (should (string-equal (file-name-nondirectory file) ""))))))) 658 (should (string-equal (file-name-directory file) file))
659 (should (string-equal (file-name-nondirectory file) ""))))))))
659 660
660(ert-deftest tramp-test07-file-exists-p () 661(ert-deftest tramp-test07-file-exists-p ()
661 "Check `file-exist-p', `write-region' and `delete-file'." 662 "Check `file-exist-p', `write-region' and `delete-file'."
@@ -1091,7 +1092,8 @@ This tests also `file-directory-p' and `file-accessible-directory-p'."
1091 1092
1092(ert-deftest tramp-test18-file-attributes () 1093(ert-deftest tramp-test18-file-attributes ()
1093 "Check `file-attributes'. 1094 "Check `file-attributes'.
1094This tests also `file-readable-p' and `file-regular-p'." 1095This tests also `file-readable-p', `file-regular-p' and
1096`file-ownership-preserved-p'."
1095 (skip-unless (tramp--test-enabled)) 1097 (skip-unless (tramp--test-enabled))
1096 1098
1097 ;; We must use `file-truename' for the temporary directory, because 1099 ;; We must use `file-truename' for the temporary directory, because
@@ -1111,10 +1113,16 @@ This tests also `file-readable-p' and `file-regular-p'."
1111 attr) 1113 attr)
1112 (unwind-protect 1114 (unwind-protect
1113 (progn 1115 (progn
1116 ;; `file-ownership-preserved-p' should return t for
1117 ;; non-existing files. It is implemented only in tramp-sh.el.
1118 (when (tramp--test-sh-p)
1119 (should (file-ownership-preserved-p tmp-name1 'group)))
1114 (write-region "foo" nil tmp-name1) 1120 (write-region "foo" nil tmp-name1)
1115 (should (file-exists-p tmp-name1)) 1121 (should (file-exists-p tmp-name1))
1116 (should (file-readable-p tmp-name1)) 1122 (should (file-readable-p tmp-name1))
1117 (should (file-regular-p tmp-name1)) 1123 (should (file-regular-p tmp-name1))
1124 (when (tramp--test-sh-p)
1125 (should (file-ownership-preserved-p tmp-name1 'group)))
1118 1126
1119 ;; We do not test inodes and device numbers. 1127 ;; We do not test inodes and device numbers.
1120 (setq attr (file-attributes tmp-name1)) 1128 (setq attr (file-attributes tmp-name1))
@@ -1138,9 +1146,13 @@ This tests also `file-readable-p' and `file-regular-p'."
1138 1146
1139 (condition-case err 1147 (condition-case err
1140 (progn 1148 (progn
1149 (when (tramp--test-sh-p)
1150 (should (file-ownership-preserved-p tmp-name2 'group)))
1141 (make-symbolic-link tmp-name1 tmp-name2) 1151 (make-symbolic-link tmp-name1 tmp-name2)
1142 (should (file-exists-p tmp-name2)) 1152 (should (file-exists-p tmp-name2))
1143 (should (file-symlink-p tmp-name2)) 1153 (should (file-symlink-p tmp-name2))
1154 (when (tramp--test-sh-p)
1155 (should (file-ownership-preserved-p tmp-name2 'group)))
1144 (setq attr (file-attributes tmp-name2)) 1156 (setq attr (file-attributes tmp-name2))
1145 (should (string-equal 1157 (should (string-equal
1146 (car attr) 1158 (car attr)
@@ -1167,11 +1179,15 @@ This tests also `file-readable-p' and `file-regular-p'."
1167 (tramp-file-name-localname (tramp-dissect-file-name tmp-name3)))) 1179 (tramp-file-name-localname (tramp-dissect-file-name tmp-name3))))
1168 (delete-file tmp-name2)) 1180 (delete-file tmp-name2))
1169 1181
1182 (when (tramp--test-sh-p)
1183 (should (file-ownership-preserved-p tmp-name1 'group)))
1170 (delete-file tmp-name1) 1184 (delete-file tmp-name1)
1171 (make-directory tmp-name1) 1185 (make-directory tmp-name1)
1172 (should (file-exists-p tmp-name1)) 1186 (should (file-exists-p tmp-name1))
1173 (should (file-readable-p tmp-name1)) 1187 (should (file-readable-p tmp-name1))
1174 (should-not (file-regular-p tmp-name1)) 1188 (should-not (file-regular-p tmp-name1))
1189 (when (tramp--test-sh-p)
1190 (should (file-ownership-preserved-p tmp-name1 'group)))
1175 (setq attr (file-attributes tmp-name1)) 1191 (setq attr (file-attributes tmp-name1))
1176 (should (eq (car attr) t))) 1192 (should (eq (car attr) t)))
1177 1193
@@ -1227,13 +1243,7 @@ This tests also `file-readable-p' and `file-regular-p'."
1227 "Check `file-modes'. 1243 "Check `file-modes'.
1228This tests also `file-executable-p', `file-writable-p' and `set-file-modes'." 1244This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
1229 (skip-unless (tramp--test-enabled)) 1245 (skip-unless (tramp--test-enabled))
1230 (skip-unless 1246 (skip-unless (tramp--test-sh-p))
1231 (not
1232 (memq
1233 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1234 '(tramp-adb-file-name-handler
1235 tramp-gvfs-file-name-handler
1236 tramp-smb-file-name-handler))))
1237 1247
1238 (let ((tmp-name (tramp--test-make-temp-name))) 1248 (let ((tmp-name (tramp--test-make-temp-name)))
1239 (unwind-protect 1249 (unwind-protect
@@ -1337,11 +1347,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
1337(ert-deftest tramp-test22-file-times () 1347(ert-deftest tramp-test22-file-times ()
1338 "Check `set-file-times' and `file-newer-than-file-p'." 1348 "Check `set-file-times' and `file-newer-than-file-p'."
1339 (skip-unless (tramp--test-enabled)) 1349 (skip-unless (tramp--test-enabled))
1340 (skip-unless 1350 (skip-unless (or (tramp--test-adb-p) (tramp--test-sh-p)))
1341 (not
1342 (memq
1343 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1344 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler))))
1345 1351
1346 (let ((tmp-name1 (tramp--test-make-temp-name)) 1352 (let ((tmp-name1 (tramp--test-make-temp-name))
1347 (tmp-name2 (tramp--test-make-temp-name)) 1353 (tmp-name2 (tramp--test-make-temp-name))
@@ -1499,11 +1505,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
1499 "Check `process-file'." 1505 "Check `process-file'."
1500 :tags '(:expensive-test) 1506 :tags '(:expensive-test)
1501 (skip-unless (tramp--test-enabled)) 1507 (skip-unless (tramp--test-enabled))
1502 (skip-unless 1508 (skip-unless (or (tramp--test-adb-p) (tramp--test-sh-p)))
1503 (not
1504 (memq
1505 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1506 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler))))
1507 1509
1508 (let* ((tmp-name (tramp--test-make-temp-name)) 1510 (let* ((tmp-name (tramp--test-make-temp-name))
1509 (fnnd (file-name-nondirectory tmp-name)) 1511 (fnnd (file-name-nondirectory tmp-name))
@@ -1548,13 +1550,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
1548 "Check `start-file-process'." 1550 "Check `start-file-process'."
1549 :tags '(:expensive-test) 1551 :tags '(:expensive-test)
1550 (skip-unless (tramp--test-enabled)) 1552 (skip-unless (tramp--test-enabled))
1551 (skip-unless 1553 (skip-unless (tramp--test-sh-p))
1552 (not
1553 (memq
1554 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1555 '(tramp-adb-file-name-handler
1556 tramp-gvfs-file-name-handler
1557 tramp-smb-file-name-handler))))
1558 1554
1559 (let ((default-directory tramp-test-temporary-file-directory) 1555 (let ((default-directory tramp-test-temporary-file-directory)
1560 (tmp-name (tramp--test-make-temp-name)) 1556 (tmp-name (tramp--test-make-temp-name))
@@ -1569,7 +1565,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
1569 ;; Read output. 1565 ;; Read output.
1570 (with-timeout (10 (ert-fail "`start-file-process' timed out")) 1566 (with-timeout (10 (ert-fail "`start-file-process' timed out"))
1571 (while (< (- (point-max) (point-min)) (length "foo")) 1567 (while (< (- (point-max) (point-min)) (length "foo"))
1572 (accept-process-output proc 1))) 1568 (accept-process-output proc 0.1)))
1573 (should (string-equal (buffer-string) "foo"))) 1569 (should (string-equal (buffer-string) "foo")))
1574 1570
1575 ;; Cleanup. 1571 ;; Cleanup.
@@ -1587,7 +1583,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
1587 ;; Read output. 1583 ;; Read output.
1588 (with-timeout (10 (ert-fail "`start-file-process' timed out")) 1584 (with-timeout (10 (ert-fail "`start-file-process' timed out"))
1589 (while (< (- (point-max) (point-min)) (length "foo")) 1585 (while (< (- (point-max) (point-min)) (length "foo"))
1590 (accept-process-output proc 1))) 1586 (accept-process-output proc 0.1)))
1591 (should (string-equal (buffer-string) "foo"))) 1587 (should (string-equal (buffer-string) "foo")))
1592 1588
1593 ;; Cleanup. 1589 ;; Cleanup.
@@ -1608,7 +1604,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
1608 ;; Read output. 1604 ;; Read output.
1609 (with-timeout (10 (ert-fail "`start-file-process' timed out")) 1605 (with-timeout (10 (ert-fail "`start-file-process' timed out"))
1610 (while (< (- (point-max) (point-min)) (length "foo")) 1606 (while (< (- (point-max) (point-min)) (length "foo"))
1611 (accept-process-output proc 1))) 1607 (accept-process-output proc 0.1)))
1612 (should (string-equal (buffer-string) "foo"))) 1608 (should (string-equal (buffer-string) "foo")))
1613 1609
1614 ;; Cleanup. 1610 ;; Cleanup.
@@ -1618,13 +1614,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
1618 "Check `shell-command'." 1614 "Check `shell-command'."
1619 :tags '(:expensive-test) 1615 :tags '(:expensive-test)
1620 (skip-unless (tramp--test-enabled)) 1616 (skip-unless (tramp--test-enabled))
1621 (skip-unless 1617 (skip-unless (tramp--test-sh-p))
1622 (not
1623 (memq
1624 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1625 '(tramp-adb-file-name-handler
1626 tramp-gvfs-file-name-handler
1627 tramp-smb-file-name-handler))))
1628 1618
1629 (let ((tmp-name (tramp--test-make-temp-name)) 1619 (let ((tmp-name (tramp--test-make-temp-name))
1630 (default-directory tramp-test-temporary-file-directory) 1620 (default-directory tramp-test-temporary-file-directory)
@@ -1657,7 +1647,8 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
1657 (with-timeout (10 (ert-fail "`async-shell-command' timed out")) 1647 (with-timeout (10 (ert-fail "`async-shell-command' timed out"))
1658 (while (< (- (point-max) (point-min)) 1648 (while (< (- (point-max) (point-min))
1659 (1+ (length (file-name-nondirectory tmp-name)))) 1649 (1+ (length (file-name-nondirectory tmp-name))))
1660 (accept-process-output (get-buffer-process (current-buffer)) 1))) 1650 (accept-process-output
1651 (get-buffer-process (current-buffer)) 0.1)))
1661 ;; `ls' could produce colorized output. 1652 ;; `ls' could produce colorized output.
1662 (goto-char (point-min)) 1653 (goto-char (point-min))
1663 (while (re-search-forward tramp-display-escape-sequence-regexp nil t) 1654 (while (re-search-forward tramp-display-escape-sequence-regexp nil t)
@@ -1686,7 +1677,8 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
1686 (with-timeout (10 (ert-fail "`async-shell-command' timed out")) 1677 (with-timeout (10 (ert-fail "`async-shell-command' timed out"))
1687 (while (< (- (point-max) (point-min)) 1678 (while (< (- (point-max) (point-min))
1688 (1+ (length (file-name-nondirectory tmp-name)))) 1679 (1+ (length (file-name-nondirectory tmp-name))))
1689 (accept-process-output (get-buffer-process (current-buffer)) 1))) 1680 (accept-process-output
1681 (get-buffer-process (current-buffer)) 0.1)))
1690 ;; `ls' could produce colorized output. 1682 ;; `ls' could produce colorized output.
1691 (goto-char (point-min)) 1683 (goto-char (point-min))
1692 (while (re-search-forward tramp-display-escape-sequence-regexp nil t) 1684 (while (re-search-forward tramp-display-escape-sequence-regexp nil t)
@@ -1708,9 +1700,10 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
1708 (async-shell-command command (current-buffer)) 1700 (async-shell-command command (current-buffer))
1709 ;; Suppress nasty messages. 1701 ;; Suppress nasty messages.
1710 (set-process-sentinel (get-buffer-process (current-buffer)) nil) 1702 (set-process-sentinel (get-buffer-process (current-buffer)) nil)
1711 (while (get-buffer-process (current-buffer)) 1703 (with-timeout (10)
1712 (accept-process-output (get-buffer-process (current-buffer)) 0.1)) 1704 (while (get-buffer-process (current-buffer))
1713 (accept-process-output) 1705 (accept-process-output (get-buffer-process (current-buffer)) 0.1)))
1706 (accept-process-output nil 0.1)
1714 (buffer-substring-no-properties (point-min) (point-max)))) 1707 (buffer-substring-no-properties (point-min) (point-max))))
1715 1708
1716;; This test is inspired by Bug#23952. 1709;; This test is inspired by Bug#23952.
@@ -1718,10 +1711,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
1718 "Check that remote processes set / unset environment variables properly." 1711 "Check that remote processes set / unset environment variables properly."
1719 :tags '(:expensive-test) 1712 :tags '(:expensive-test)
1720 (skip-unless (tramp--test-enabled)) 1713 (skip-unless (tramp--test-enabled))
1721 (skip-unless 1714 (skip-unless (tramp--test-sh-p))
1722 (eq
1723 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1724 'tramp-sh-file-name-handler))
1725 1715
1726 (dolist (this-shell-command-to-string 1716 (dolist (this-shell-command-to-string
1727 '(;; Synchronously. 1717 '(;; Synchronously.
@@ -1798,10 +1788,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
1798 "Check `vc-registered'." 1788 "Check `vc-registered'."
1799 :tags '(:expensive-test) 1789 :tags '(:expensive-test)
1800 (skip-unless (tramp--test-enabled)) 1790 (skip-unless (tramp--test-enabled))
1801 (skip-unless 1791 (skip-unless (tramp--test-sh-p))
1802 (eq
1803 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1804 'tramp-sh-file-name-handler))
1805 1792
1806 (let* ((default-directory tramp-test-temporary-file-directory) 1793 (let* ((default-directory tramp-test-temporary-file-directory)
1807 (tmp-name1 (tramp--test-make-temp-name)) 1794 (tmp-name1 (tramp--test-make-temp-name))
@@ -1947,6 +1934,36 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
1947 (ignore-errors (delete-file tmp-name1)) 1934 (ignore-errors (delete-file tmp-name1))
1948 (ignore-errors (delete-directory tmp-name2 'recursive))))) 1935 (ignore-errors (delete-directory tmp-name2 'recursive)))))
1949 1936
1937(ert-deftest tramp-test32-make-nearby-temp-file ()
1938 "Check `make-nearby-temp-file' and `temporary-file-directory'."
1939 (skip-unless (tramp--test-enabled))
1940
1941 (let ((default-directory tramp-test-temporary-file-directory)
1942 tmp-file)
1943 ;; The remote host shall know a tempory file directory.
1944 (should (stringp (temporary-file-directory)))
1945 (should
1946 (string-equal
1947 (file-remote-p default-directory)
1948 (file-remote-p (temporary-file-directory))))
1949
1950 ;; The temporary file shall be located on the remote host.
1951 (setq tmp-file (make-nearby-temp-file "tramp-test"))
1952 (should (file-exists-p tmp-file))
1953 (should (file-regular-p tmp-file))
1954 (should
1955 (string-equal
1956 (file-remote-p default-directory)
1957 (file-remote-p tmp-file)))
1958 (delete-file tmp-file)
1959 (should-not (file-exists-p tmp-file))
1960
1961 (setq tmp-file (make-nearby-temp-file "tramp-test" 'dir))
1962 (should (file-exists-p tmp-file))
1963 (should (file-directory-p tmp-file))
1964 (delete-directory tmp-file)
1965 (should-not (file-exists-p tmp-file))))
1966
1950(defun tramp--test-adb-p () 1967(defun tramp--test-adb-p ()
1951 "Check, whether the remote host runs Android. 1968 "Check, whether the remote host runs Android.
1952This requires restrictions of file name syntax." 1969This requires restrictions of file name syntax."
@@ -1956,11 +1973,13 @@ This requires restrictions of file name syntax."
1956 "Check, whether an FTP-like method is used. 1973 "Check, whether an FTP-like method is used.
1957This does not support globbing characters in file names (yet)." 1974This does not support globbing characters in file names (yet)."
1958 ;; Globbing characters are ??, ?* and ?\[. 1975 ;; Globbing characters are ??, ?* and ?\[.
1959 (and (eq (tramp-find-foreign-file-name-handler 1976 (string-match
1960 tramp-test-temporary-file-directory) 1977 "ftp$" (file-remote-p tramp-test-temporary-file-directory 'method)))
1961 'tramp-sh-file-name-handler) 1978
1962 (string-match 1979(defun tramp--test-gvfs-p ()
1963 "ftp$" (file-remote-p tramp-test-temporary-file-directory 'method)))) 1980 "Check, whether the remote host runs a GVFS based method.
1981This requires restrictions of file name syntax."
1982 (tramp-gvfs-file-name-p tramp-test-temporary-file-directory))
1964 1983
1965(defun tramp--test-rsync-p () 1984(defun tramp--test-rsync-p ()
1966 "Check, whether the rsync method is used. 1985 "Check, whether the rsync method is used.
@@ -1968,10 +1987,11 @@ This does not support special file names."
1968 (string-equal 1987 (string-equal
1969 "rsync" (file-remote-p tramp-test-temporary-file-directory 'method))) 1988 "rsync" (file-remote-p tramp-test-temporary-file-directory 'method)))
1970 1989
1971(defun tramp--test-gvfs-p () 1990(defun tramp--test-sh-p ()
1972 "Check, whether the remote host runs a GVFS based method. 1991 "Check, whether the remote host runs a based method from tramp-sh.el."
1973This requires restrictions of file name syntax." 1992 (eq
1974 (tramp-gvfs-file-name-p tramp-test-temporary-file-directory)) 1993 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1994 'tramp-sh-file-name-handler))
1975 1995
1976(defun tramp--test-smb-or-windows-nt-p () 1996(defun tramp--test-smb-or-windows-nt-p ()
1977 "Check, whether the locale or remote host runs MS Windows. 1997 "Check, whether the locale or remote host runs MS Windows.
@@ -2123,7 +2143,7 @@ Several special characters do not work properly there."
2123 (ignore-errors (delete-directory tmp-name2 'recursive))))) 2143 (ignore-errors (delete-directory tmp-name2 'recursive)))))
2124 2144
2125(defun tramp--test-special-characters () 2145(defun tramp--test-special-characters ()
2126 "Perform the test in `tramp-test32-special-characters*'." 2146 "Perform the test in `tramp-test33-special-characters*'."
2127 ;; Newlines, slashes and backslashes in file names are not 2147 ;; Newlines, slashes and backslashes in file names are not
2128 ;; supported. So we don't test. And we don't test the tab 2148 ;; supported. So we don't test. And we don't test the tab
2129 ;; character on Windows or Cygwin, because the backslash is 2149 ;; character on Windows or Cygwin, because the backslash is
@@ -2164,23 +2184,19 @@ Several special characters do not work properly there."
2164 "{foo}bar{baz}")) 2184 "{foo}bar{baz}"))
2165 2185
2166;; These tests are inspired by Bug#17238. 2186;; These tests are inspired by Bug#17238.
2167(ert-deftest tramp-test32-special-characters () 2187(ert-deftest tramp-test33-special-characters ()
2168 "Check special characters in file names." 2188 "Check special characters in file names."
2169 (skip-unless (tramp--test-enabled)) 2189 (skip-unless (tramp--test-enabled))
2170 (skip-unless (not (tramp--test-rsync-p))) 2190 (skip-unless (not (tramp--test-rsync-p)))
2171 2191
2172 (tramp--test-special-characters)) 2192 (tramp--test-special-characters))
2173 2193
2174(ert-deftest tramp-test32-special-characters-with-stat () 2194(ert-deftest tramp-test33-special-characters-with-stat ()
2175 "Check special characters in file names. 2195 "Check special characters in file names.
2176Use the `stat' command." 2196Use the `stat' command."
2177 :tags '(:expensive-test) 2197 :tags '(:expensive-test)
2178 (skip-unless (tramp--test-enabled)) 2198 (skip-unless (tramp--test-enabled))
2179 (skip-unless (not (tramp--test-rsync-p))) 2199 (skip-unless (and (tramp--test-sh-p) (not (tramp--test-rsync-p))))
2180 (skip-unless
2181 (eq
2182 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
2183 'tramp-sh-file-name-handler))
2184 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil 2200 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
2185 (skip-unless (tramp-get-remote-stat v))) 2201 (skip-unless (tramp-get-remote-stat v)))
2186 2202
@@ -2191,16 +2207,12 @@ Use the `stat' command."
2191 tramp-connection-properties))) 2207 tramp-connection-properties)))
2192 (tramp--test-special-characters))) 2208 (tramp--test-special-characters)))
2193 2209
2194(ert-deftest tramp-test32-special-characters-with-perl () 2210(ert-deftest tramp-test33-special-characters-with-perl ()
2195 "Check special characters in file names. 2211 "Check special characters in file names.
2196Use the `perl' command." 2212Use the `perl' command."
2197 :tags '(:expensive-test) 2213 :tags '(:expensive-test)
2198 (skip-unless (tramp--test-enabled)) 2214 (skip-unless (tramp--test-enabled))
2199 (skip-unless (not (tramp--test-rsync-p))) 2215 (skip-unless (and (tramp--test-sh-p) (not (tramp--test-rsync-p))))
2200 (skip-unless
2201 (eq
2202 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
2203 'tramp-sh-file-name-handler))
2204 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil 2216 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
2205 (skip-unless (tramp-get-remote-perl v))) 2217 (skip-unless (tramp-get-remote-perl v)))
2206 2218
@@ -2214,16 +2226,12 @@ Use the `perl' command."
2214 tramp-connection-properties))) 2226 tramp-connection-properties)))
2215 (tramp--test-special-characters))) 2227 (tramp--test-special-characters)))
2216 2228
2217(ert-deftest tramp-test32-special-characters-with-ls () 2229(ert-deftest tramp-test33-special-characters-with-ls ()
2218 "Check special characters in file names. 2230 "Check special characters in file names.
2219Use the `ls' command." 2231Use the `ls' command."
2220 :tags '(:expensive-test) 2232 :tags '(:expensive-test)
2221 (skip-unless (tramp--test-enabled)) 2233 (skip-unless (tramp--test-enabled))
2222 (skip-unless (not (tramp--test-rsync-p))) 2234 (skip-unless (and (tramp--test-sh-p) (not (tramp--test-rsync-p))))
2223 (skip-unless
2224 (eq
2225 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
2226 'tramp-sh-file-name-handler))
2227 2235
2228 (let ((tramp-connection-properties 2236 (let ((tramp-connection-properties
2229 (append 2237 (append
@@ -2238,7 +2246,7 @@ Use the `ls' command."
2238 (tramp--test-special-characters))) 2246 (tramp--test-special-characters)))
2239 2247
2240(defun tramp--test-utf8 () 2248(defun tramp--test-utf8 ()
2241 "Perform the test in `tramp-test33-utf8*'." 2249 "Perform the test in `tramp-test34-utf8*'."
2242 (let* ((utf8 (if (and (eq system-type 'darwin) 2250 (let* ((utf8 (if (and (eq system-type 'darwin)
2243 (memq 'utf-8-hfs (coding-system-list))) 2251 (memq 'utf-8-hfs (coding-system-list)))
2244 'utf-8-hfs 'utf-8)) 2252 'utf-8-hfs 'utf-8))
@@ -2252,23 +2260,19 @@ Use the `ls' command."
2252 "银河系漫游指南系列" 2260 "银河系漫游指南系列"
2253 "Автостопом по гала́ктике"))) 2261 "Автостопом по гала́ктике")))
2254 2262
2255(ert-deftest tramp-test33-utf8 () 2263(ert-deftest tramp-test34-utf8 ()
2256 "Check UTF8 encoding in file names and file contents." 2264 "Check UTF8 encoding in file names and file contents."
2257 (skip-unless (tramp--test-enabled)) 2265 (skip-unless (tramp--test-enabled))
2258 (skip-unless (not (tramp--test-rsync-p))) 2266 (skip-unless (not (tramp--test-rsync-p)))
2259 2267
2260 (tramp--test-utf8)) 2268 (tramp--test-utf8))
2261 2269
2262(ert-deftest tramp-test33-utf8-with-stat () 2270(ert-deftest tramp-test34-utf8-with-stat ()
2263 "Check UTF8 encoding in file names and file contents. 2271 "Check UTF8 encoding in file names and file contents.
2264Use the `stat' command." 2272Use the `stat' command."
2265 :tags '(:expensive-test) 2273 :tags '(:expensive-test)
2266 (skip-unless (tramp--test-enabled)) 2274 (skip-unless (tramp--test-enabled))
2267 (skip-unless (not (tramp--test-rsync-p))) 2275 (skip-unless (and (tramp--test-sh-p) (not (tramp--test-rsync-p))))
2268 (skip-unless
2269 (eq
2270 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
2271 'tramp-sh-file-name-handler))
2272 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil 2276 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
2273 (skip-unless (tramp-get-remote-stat v))) 2277 (skip-unless (tramp-get-remote-stat v)))
2274 2278
@@ -2279,16 +2283,12 @@ Use the `stat' command."
2279 tramp-connection-properties))) 2283 tramp-connection-properties)))
2280 (tramp--test-utf8))) 2284 (tramp--test-utf8)))
2281 2285
2282(ert-deftest tramp-test33-utf8-with-perl () 2286(ert-deftest tramp-test34-utf8-with-perl ()
2283 "Check UTF8 encoding in file names and file contents. 2287 "Check UTF8 encoding in file names and file contents.
2284Use the `perl' command." 2288Use the `perl' command."
2285 :tags '(:expensive-test) 2289 :tags '(:expensive-test)
2286 (skip-unless (tramp--test-enabled)) 2290 (skip-unless (tramp--test-enabled))
2287 (skip-unless (not (tramp--test-rsync-p))) 2291 (skip-unless (and (tramp--test-sh-p) (not (tramp--test-rsync-p))))
2288 (skip-unless
2289 (eq
2290 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
2291 'tramp-sh-file-name-handler))
2292 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil 2292 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
2293 (skip-unless (tramp-get-remote-perl v))) 2293 (skip-unless (tramp-get-remote-perl v)))
2294 2294
@@ -2302,16 +2302,12 @@ Use the `perl' command."
2302 tramp-connection-properties))) 2302 tramp-connection-properties)))
2303 (tramp--test-utf8))) 2303 (tramp--test-utf8)))
2304 2304
2305(ert-deftest tramp-test33-utf8-with-ls () 2305(ert-deftest tramp-test34-utf8-with-ls ()
2306 "Check UTF8 encoding in file names and file contents. 2306 "Check UTF8 encoding in file names and file contents.
2307Use the `ls' command." 2307Use the `ls' command."
2308 :tags '(:expensive-test) 2308 :tags '(:expensive-test)
2309 (skip-unless (tramp--test-enabled)) 2309 (skip-unless (tramp--test-enabled))
2310 (skip-unless (not (tramp--test-rsync-p))) 2310 (skip-unless (and (tramp--test-sh-p) (not (tramp--test-rsync-p))))
2311 (skip-unless
2312 (eq
2313 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
2314 'tramp-sh-file-name-handler))
2315 2311
2316 (let ((tramp-connection-properties 2312 (let ((tramp-connection-properties
2317 (append 2313 (append
@@ -2326,7 +2322,7 @@ Use the `ls' command."
2326 (tramp--test-utf8))) 2322 (tramp--test-utf8)))
2327 2323
2328;; This test is inspired by Bug#16928. 2324;; This test is inspired by Bug#16928.
2329(ert-deftest tramp-test34-asynchronous-requests () 2325(ert-deftest tramp-test35-asynchronous-requests ()
2330 "Check parallel asynchronous requests. 2326 "Check parallel asynchronous requests.
2331Such requests could arrive from timers, process filters and 2327Such requests could arrive from timers, process filters and
2332process sentinels. They shall not disturb each other." 2328process sentinels. They shall not disturb each other."
@@ -2334,10 +2330,7 @@ process sentinels. They shall not disturb each other."
2334 :expected-result :failed 2330 :expected-result :failed
2335 :tags '(:expensive-test) 2331 :tags '(:expensive-test)
2336 (skip-unless (tramp--test-enabled)) 2332 (skip-unless (tramp--test-enabled))
2337 (skip-unless 2333 (skip-unless (tramp--test-sh-p))
2338 (eq
2339 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
2340 'tramp-sh-file-name-handler))
2341 2334
2342 ;; Keep instrumentation verbosity 0 until Tramp bug is fixed. This 2335 ;; Keep instrumentation verbosity 0 until Tramp bug is fixed. This
2343 ;; has the side effect, that this test fails instead to abort. Good 2336 ;; has the side effect, that this test fails instead to abort. Good
@@ -2416,7 +2409,7 @@ process sentinels. They shall not disturb each other."
2416 (dolist (buf buffers) 2409 (dolist (buf buffers)
2417 (ignore-errors (kill-buffer buf))))))) 2410 (ignore-errors (kill-buffer buf)))))))
2418 2411
2419(ert-deftest tramp-test35-recursive-load () 2412(ert-deftest tramp-test36-recursive-load ()
2420 "Check that Tramp does not fail due to recursive load." 2413 "Check that Tramp does not fail due to recursive load."
2421 (skip-unless (tramp--test-enabled)) 2414 (skip-unless (tramp--test-enabled))
2422 2415
@@ -2439,7 +2432,7 @@ process sentinels. They shall not disturb each other."
2439 (mapconcat 'shell-quote-argument load-path " -L ") 2432 (mapconcat 'shell-quote-argument load-path " -L ")
2440 (shell-quote-argument code))))))) 2433 (shell-quote-argument code)))))))
2441 2434
2442(ert-deftest tramp-test36-unload () 2435(ert-deftest tramp-test37-unload ()
2443 "Check that Tramp and its subpackages unload completely. 2436 "Check that Tramp and its subpackages unload completely.
2444Since it unloads Tramp, it shall be the last test to run." 2437Since it unloads Tramp, it shall be the last test to run."
2445 ;; Mark as failed until all symbols are unbound. 2438 ;; Mark as failed until all symbols are unbound.
@@ -2477,7 +2470,6 @@ Since it unloads Tramp, it shall be the last test to run."
2477;; * dired-compress-file 2470;; * dired-compress-file
2478;; * dired-uncache 2471;; * dired-uncache
2479;; * file-acl 2472;; * file-acl
2480;; * file-ownership-preserved-p
2481;; * file-selinux-context 2473;; * file-selinux-context
2482;; * find-backup-file-name 2474;; * find-backup-file-name
2483;; * set-file-acl 2475;; * set-file-acl
@@ -2485,10 +2477,9 @@ Since it unloads Tramp, it shall be the last test to run."
2485 2477
2486;; * Work on skipped tests. Make a comment, when it is impossible. 2478;; * Work on skipped tests. Make a comment, when it is impossible.
2487;; * Fix `tramp-test06-directory-file-name' for `ftp'. 2479;; * Fix `tramp-test06-directory-file-name' for `ftp'.
2488;; * Fix `tramp-test15-copy-directory' for `rsync'.
2489;; * Fix `tramp-test27-start-file-process' on MS Windows (`process-send-eof'?). 2480;; * Fix `tramp-test27-start-file-process' on MS Windows (`process-send-eof'?).
2490;; * Fix Bug#16928. Set expected error of `tramp-test34-asynchronous-requests'. 2481;; * Fix Bug#16928. Set expected error of `tramp-test35-asynchronous-requests'.
2491;; * Fix `tramp-test36-unload' (Not all symbols are unbound). Set 2482;; * Fix `tramp-test37-unload' (Not all symbols are unbound). Set
2492;; expected error. 2483;; expected error.
2493 2484
2494(defun tramp-test-all (&optional interactive) 2485(defun tramp-test-all (&optional interactive)