;; We depend on being the last handler on the list,
;; so that anything else which does need handling
;; has been handled already.
-;; So it is safe for us to inhibit *all* magic file name handlers.
+;; So it is safe for us to inhibit *all* magic file name handlers for
+;; operations, which return a file name. See Bug#29579.
(defun file-name-non-special (operation &rest arguments)
- (let ((file-name-handler-alist nil)
- (default-directory
- ;; Some operations respect file name handlers in
- ;; `default-directory'. Because core function like
- ;; `call-process' don't care about file name handlers in
- ;; `default-directory', we here have to resolve the
- ;; directory into a local one. For `process-file',
- ;; `start-file-process', and `shell-command', this fixes
- ;; Bug#25949.
- (if (memq operation '(insert-directory process-file start-file-process
- shell-command))
- (directory-file-name
- (expand-file-name
- (unhandled-file-name-directory default-directory)))
- default-directory))
- ;; Get a list of the indices of the args which are file names.
- (file-arg-indices
- (cdr (or (assq operation
- ;; The first six are special because they
- ;; return a file name. We want to include the /:
- ;; in the return value.
- ;; So just avoid stripping it in the first place.
- '((expand-file-name . nil)
- (file-name-directory . nil)
- (file-name-as-directory . nil)
- (directory-file-name . nil)
- (file-name-sans-versions . nil)
- (find-backup-file-name . nil)
- ;; `identity' means just return the first arg
- ;; not stripped of its quoting.
- (substitute-in-file-name identity)
- ;; `add' means add "/:" to the result.
- (file-truename add 0)
- (insert-file-contents insert-file-contents 0)
- ;; `unquote-then-quote' means set buffer-file-name
- ;; temporarily to unquoted filename.
- (verify-visited-file-modtime unquote-then-quote)
- ;; List the arguments which are filenames.
- (file-name-completion 1)
- (file-name-all-completions 1)
- (write-region 2 5)
- (rename-file 0 1)
- (copy-file 0 1)
- (make-symbolic-link 0 1)
- (add-name-to-file 0 1)))
- ;; For all other operations, treat the first argument only
- ;; as the file name.
- '(nil 0))))
- method
- ;; Copy ARGUMENTS so we can replace elements in it.
- (arguments (copy-sequence arguments)))
+ (let* ((op-returns-file-name-list
+ '(expand-file-name file-name-directory file-name-as-directory
+ directory-file-name file-name-sans-versions
+ find-backup-file-name file-remote-p))
+ (file-name-handler-alist
+ (and
+ (not (memq operation op-returns-file-name-list))
+ file-name-handler-alist))
+ (default-directory
+ ;; Some operations respect file name handlers in
+ ;; `default-directory'. Because core function like
+ ;; `call-process' don't care about file name handlers in
+ ;; `default-directory', we here have to resolve the
+ ;; directory into a local one. For `process-file',
+ ;; `start-file-process', and `shell-command', this fixes
+ ;; Bug#25949.
+ (if (memq operation
+ '(insert-directory process-file start-file-process
+ shell-command))
+ (directory-file-name
+ (expand-file-name
+ (unhandled-file-name-directory default-directory)))
+ default-directory))
+ ;; Get a list of the indices of the args which are file names.
+ (file-arg-indices
+ (cdr (or (assq operation
+ ;; The first seven are special because they
+ ;; return a file name. We want to include the /:
+ ;; in the return value.
+ ;; So just avoid stripping it in the first place.
+ (append
+ (mapcar 'list op-returns-file-name-list)
+ '(;; `identity' means just return the first arg
+ ;; not stripped of its quoting.
+ (substitute-in-file-name identity)
+ ;; `add' means add "/:" to the result.
+ (file-truename add 0)
+ (insert-file-contents insert-file-contents 0)
+ ;; `unquote-then-quote' means set buffer-file-name
+ ;; temporarily to unquoted filename.
+ (verify-visited-file-modtime unquote-then-quote)
+ ;; List the arguments which are filenames.
+ (file-name-completion 1)
+ (file-name-all-completions 1)
+ (write-region 2 5)
+ (rename-file 0 1)
+ (copy-file 0 1)
+ (copy-directory 0 1)
+ (file-in-directory-p 0 1)
+ (make-symbolic-link 0 1)
+ (add-name-to-file 0 1))))
+ ;; For all other operations, treat the first argument only
+ ;; as the file name.
+ '(nil 0))))
+ method
+ ;; Copy ARGUMENTS so we can replace elements in it.
+ (arguments (copy-sequence arguments)))
(if (symbolp (car file-arg-indices))
(setq method (pop file-arg-indices)))
;; Strip off the /: from the file names that have it.
(defsubst tramp-compat-file-name-quote (name)
"Add the quotation prefix \"/:\" to file NAME.
If NAME is a remote file name, the local part of NAME is quoted."
- (concat
- (file-remote-p name) "/:" (or (file-remote-p name 'localname) name))))
+ (if (tramp-compat-file-name-quoted-p name)
+ name
+ (concat
+ (file-remote-p name) "/:" (or (file-remote-p name 'localname) name)))))
(if (fboundp 'file-name-unquote)
(defalias 'tramp-compat-file-name-unquote 'file-name-unquote)
(load . tramp-handle-load)
(make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
(make-directory . tramp-sh-handle-make-directory)
+ ;; `make-directory-internal' performed by default handler.
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-symbolic-link . tramp-sh-handle-make-symbolic-link)
(process-file . tramp-sh-handle-process-file)
(delete-directory tmpdir 'recursive))))
;; We can copy recursively.
- ;; Does not work reliably.
+ ;; TODO: Does not work reliably.
(nil ;(and (or t1 t2) (tramp-smb-get-cifs-capabilities v))
(when (and (file-directory-p newname)
(not (string-equal (file-name-nondirectory dirname)
(save-match-data
(let ((base (file-name-nondirectory filename))
;; We should not destroy the cache entry.
- (entries (copy-sequence
+ (entries (copy-tree
(tramp-smb-get-file-entries
(file-name-directory filename))))
(avail (get-free-disk-space filename))
(tramp-set-connection-property
v "process-buffer" (current-buffer))
- ;; Use an asynchronous processes. By this, password can
+ ;; Use an asynchronous process. By this, password can
;; be handled.
(let ((p (apply
'start-process
(set-process-query-on-exit-flag p nil)
(tramp-process-actions p v nil tramp-smb-actions-set-acl)
(goto-char (point-max))
+ ;; This is meant for traces, and returning from the
+ ;; function. No error is propagated outside, due to
+ ;; the `ignore-errors' closure.
(unless (re-search-backward "tramp_exit_status [0-9]+" nil t)
(tramp-error
v 'file-error
(tramp-error
v1 'file-error
"Maximum number (%d) of symlinks exceeded" numchase-limit)))
- result))
+ (directory-file-name result)))
;; Preserve trailing "/".
(if (string-equal (file-name-nondirectory filename) "") "/" ""))))
"Check `copy-file'."
(skip-unless (tramp--test-enabled))
- ;; TODO: The quoted case does not work. Copy local file to remote.
- ;;(dolist (quoted (if tramp--test-expensive-test '(nil t) '(nil)))
- (let (quoted)
+ ;; `filename-non-special' has been fixed in Emacs 26.1, see Bug#29579.
+ (dolist (quoted (if (and tramp--test-expensive-test (tramp--test-emacs26-p))
+ '(nil t) '(nil)))
(let ((tmp-name1 (tramp--test-make-temp-name nil quoted))
(tmp-name2 (tramp--test-make-temp-name nil quoted))
(tmp-name3 (tramp--test-make-temp-name 'local quoted)))
"Check `rename-file'."
(skip-unless (tramp--test-enabled))
- ;; TODO: The quoted case does not work.
- ;;(dolist (quoted (if tramp--test-expensive-test '(nil t) '(nil)))
- (let (quoted)
+ ;; `filename-non-special' has been fixed in Emacs 26.1, see Bug#29579.
+ (dolist (quoted (if (and tramp--test-expensive-test (tramp--test-emacs26-p))
+ '(nil t) '(nil)))
(let ((tmp-name1 (tramp--test-make-temp-name nil quoted))
(tmp-name2 (tramp--test-make-temp-name nil quoted))
(tmp-name3 (tramp--test-make-temp-name 'local quoted)))
;; We must unquote it.
(should
(string-equal
- (file-truename tmp-name1)
+ (tramp-compat-file-name-unquote (file-truename tmp-name1))
(tramp-compat-file-name-unquote (file-truename tmp-name3)))))
;; Cleanup.
(skip-unless (tramp--test-enabled))
(skip-unless (file-acl tramp-test-temporary-file-directory))
- ;; TODO: The quoted case does not work. Copy local file to remote.
- ;;(dolist (quoted (if tramp--test-expensive-test '(nil t) '(nil)))
- (let (quoted)
+ ;; `filename-non-special' has been fixed in Emacs 26.1, see Bug#29579.
+ (dolist (quoted (if (and tramp--test-expensive-test (tramp--test-emacs26-p))
+ '(nil t) '(nil)))
(let ((tmp-name1 (tramp--test-make-temp-name nil quoted))
(tmp-name2 (tramp--test-make-temp-name nil quoted))
(tmp-name3 (tramp--test-make-temp-name 'local quoted)))
(should (file-acl tmp-name2))
(should (string-equal (file-acl tmp-name1) (file-acl tmp-name2)))
;; Different permissions mean different ACLs.
- (set-file-modes tmp-name1 #o777)
- (set-file-modes tmp-name2 #o444)
- (should-not
- (string-equal (file-acl tmp-name1) (file-acl tmp-name2)))
- ;; Copy ACL.
- (should (set-file-acl tmp-name2 (file-acl tmp-name1)))
- (should (string-equal (file-acl tmp-name1) (file-acl tmp-name2)))
+ (when (not (tramp--test-windows-nt-or-smb-p))
+ (set-file-modes tmp-name1 #o777)
+ (set-file-modes tmp-name2 #o444)
+ (should-not
+ (string-equal (file-acl tmp-name1) (file-acl tmp-name2))))
+ ;; Copy ACL. Not all remote handlers support it, so we test.
+ (when (set-file-acl tmp-name2 (file-acl tmp-name1))
+ (should (string-equal (file-acl tmp-name1) (file-acl tmp-name2))))
;; An invalid ACL does not harm.
(should-not (set-file-acl tmp-name2 "foo")))
(not (equal (file-selinux-context tramp-test-temporary-file-directory)
'(nil nil nil nil))))
- ;; TODO: The quoted case does not work. Copy local file to remote.
- ;;(dolist (quoted (if tramp--test-expensive-test '(nil t) '(nil)))
- (let (quoted)
+ ;; `filename-non-special' has been fixed in Emacs 26.1, see Bug#29579.
+ (dolist (quoted (if (and tramp--test-expensive-test (tramp--test-emacs26-p))
+ '(nil t) '(nil)))
(let ((tmp-name1 (tramp--test-make-temp-name nil quoted))
(tmp-name2 (tramp--test-make-temp-name nil quoted))
(tmp-name3 (tramp--test-make-temp-name 'local quoted)))
(format "#%s#" (file-name-nondirectory tmp-name1))
tramp-test-temporary-file-directory))))))
- ;; TODO: The following two cases don't work yet.
- (when nil
;; Use default `tramp-auto-save-directory' mechanism.
(let ((tramp-auto-save-directory tmp-name2))
(with-temp-buffer
(tramp-compat-file-name-unquote tmp-name1)))
tmp-name2)))
(should (file-directory-p tmp-name2)))))
- ) ;; TODO
;; Cleanup.
(ignore-errors (delete-file tmp-name1))
(defun tramp--test-check-files (&rest files)
"Run a simple but comprehensive test over every file in FILES."
- ;; TODO: The quoted case does not work.
- ;;(dolist (quoted (if tramp--test-expensive-test '(nil t) '(nil)))
- (let (quoted)
+ ;; `filename-non-special' has been fixed in Emacs 26.1, see Bug#29579.
+ (dolist (quoted (if (and tramp--test-expensive-test (tramp--test-emacs26-p))
+ '(nil t) '(nil)))
;; We must use `file-truename' for the temporary directory,
;; because it could be located on a symlinked directory. This
;; would let the test fail.