Commit 4a93e698 authored by Michael Albinus's avatar Michael Albinus
Browse files

Continue reorganization of load dependencies. (Bug#7156)

* net/tramp.el (tramp-handle-file-local-copy-hook)
(tramp-delete-temp-file-function): Move down.
(tramp-exists-file-name-handler): Move up.
(tramp-register-file-name-handlers): Simplify autoload.
(tramp-handle-write-region-hook, tramp-handle-directory-file-name)
(tramp-handle-directory-files, tramp-handle-dired-uncache)
(tramp-handle-file-modes, tramp-handle-file-name-as-directory)
(tramp-handle-file-name-completion)
(tramp-handle-file-name-directory)
(tramp-handle-file-name-nondirectory, tramp-handle-file-regular-p)
(tramp-handle-file-remote-p, tramp-handle-file-symlink-p)
(tramp-handle-find-backup-file-name)
(tramp-handle-insert-file-contents, tramp-handle-load)
(tramp-handle-substitute-in-file-name)
(tramp-handle-unhandled-file-name-directory)
(tramp-mode-string-to-int, tramp-local-host-p)
(tramp-make-tramp-temp-file): Moved from tramp-sh.el.

* net/tramp-gvfs.el (top):
* net/tramp-smb.el (top): Do not require 'tramp-sh.

* net/tramp-sh.el (all): Move several objects to tramp.el, see
there.  Rename `tramp-handle-*' to `tramp-sh-handle-*'.
parent d23832a2
2010-10-04 Michael Albinus <michael.albinus@gmx.de>
Continue reorganization of load dependencies. (Bug#7156)
* net/tramp.el (tramp-handle-file-local-copy-hook)
(tramp-delete-temp-file-function): Move down.
(tramp-exists-file-name-handler): Move up.
(tramp-register-file-name-handlers): Simplify autoload.
(tramp-handle-write-region-hook, tramp-handle-directory-file-name)
(tramp-handle-directory-files, tramp-handle-dired-uncache)
(tramp-handle-file-modes, tramp-handle-file-name-as-directory)
(tramp-handle-file-name-completion)
(tramp-handle-file-name-directory)
(tramp-handle-file-name-nondirectory, tramp-handle-file-regular-p)
(tramp-handle-file-remote-p, tramp-handle-file-symlink-p)
(tramp-handle-find-backup-file-name)
(tramp-handle-insert-file-contents, tramp-handle-load)
(tramp-handle-substitute-in-file-name)
(tramp-handle-unhandled-file-name-directory)
(tramp-mode-string-to-int, tramp-local-host-p)
(tramp-make-tramp-temp-file): Moved from tramp-sh.el.
* net/tramp-gvfs.el (top):
* net/tramp-smb.el (top): Do not require 'tramp-sh.
* net/tramp-sh.el (all): Move several objects to tramp.el, see
there. Rename `tramp-handle-*' to `tramp-sh-handle-*'.
2010-10-04 Glenn Morris <rgm@gnu.org> 2010-10-04 Glenn Morris <rgm@gnu.org>
* calendar/appt.el (appt-add): Ensure reminders are enabled. * calendar/appt.el (appt-add): Ensure reminders are enabled.
......
...@@ -104,10 +104,6 @@ ...@@ -104,10 +104,6 @@
(require 'tramp) (require 'tramp)
;; We call several `tramp-handle-*' functions directly. So we must
;; reqire that package as well.
(require 'tramp-sh)
(require 'dbus) (require 'dbus)
(require 'url-parse) (require 'url-parse)
(require 'url-util) (require 'url-util)
...@@ -405,6 +401,7 @@ Every entry is a list (NAME ADDRESS).") ...@@ -405,6 +401,7 @@ Every entry is a list (NAME ADDRESS).")
(file-name-directory . tramp-handle-file-name-directory) (file-name-directory . tramp-handle-file-name-directory)
(file-name-nondirectory . tramp-handle-file-name-nondirectory) (file-name-nondirectory . tramp-handle-file-name-nondirectory)
;; `file-name-sans-versions' performed by default handler. ;; `file-name-sans-versions' performed by default handler.
;; CCC: Must be checked!
(file-newer-than-file-p . tramp-handle-file-newer-than-file-p) (file-newer-than-file-p . tramp-handle-file-newer-than-file-p)
(file-ownership-preserved-p . ignore) (file-ownership-preserved-p . ignore)
(file-readable-p . tramp-gvfs-handle-file-readable-p) (file-readable-p . tramp-gvfs-handle-file-readable-p)
......
...@@ -620,7 +620,7 @@ passed to `format', so percent characters need to be doubled.") ...@@ -620,7 +620,7 @@ passed to `format', so percent characters need to be doubled.")
;; unless this spits out a complete line, including the '\n' at the ;; unless this spits out a complete line, including the '\n' at the
;; end. ;; end.
;; The device number is returned as "-1", because there will be a virtual ;; The device number is returned as "-1", because there will be a virtual
;; device number set in `tramp-handle-file-attributes'. ;; device number set in `tramp-sh-handle-file-attributes'.
(defconst tramp-perl-file-attributes (defconst tramp-perl-file-attributes
"%s -e ' "%s -e '
@stat = lstat($ARGV[0]); @stat = lstat($ARGV[0]);
...@@ -867,62 +867,63 @@ This is used to map a mode number to a permission string.") ...@@ -867,62 +867,63 @@ This is used to map a mode number to a permission string.")
;; get-file-buffer. ;; get-file-buffer.
(defconst tramp-sh-file-name-handler-alist (defconst tramp-sh-file-name-handler-alist
'((load . tramp-handle-load) '((load . tramp-handle-load)
(make-symbolic-link . tramp-handle-make-symbolic-link) (make-symbolic-link . tramp-sh-handle-make-symbolic-link)
(file-name-as-directory . tramp-handle-file-name-as-directory) (file-name-as-directory . tramp-handle-file-name-as-directory)
(file-name-directory . tramp-handle-file-name-directory) (file-name-directory . tramp-handle-file-name-directory)
(file-name-nondirectory . tramp-handle-file-name-nondirectory) (file-name-nondirectory . tramp-handle-file-name-nondirectory)
(file-truename . tramp-handle-file-truename) (file-truename . tramp-sh-handle-file-truename)
(file-exists-p . tramp-handle-file-exists-p) (file-exists-p . tramp-sh-handle-file-exists-p)
(file-directory-p . tramp-handle-file-directory-p) (file-directory-p . tramp-sh-handle-file-directory-p)
(file-executable-p . tramp-handle-file-executable-p) (file-executable-p . tramp-sh-handle-file-executable-p)
(file-readable-p . tramp-handle-file-readable-p) (file-readable-p . tramp-sh-handle-file-readable-p)
(file-regular-p . tramp-handle-file-regular-p) (file-regular-p . tramp-handle-file-regular-p)
(file-symlink-p . tramp-handle-file-symlink-p) (file-symlink-p . tramp-handle-file-symlink-p)
(file-writable-p . tramp-handle-file-writable-p) (file-writable-p . tramp-sh-handle-file-writable-p)
(file-ownership-preserved-p . tramp-handle-file-ownership-preserved-p) (file-ownership-preserved-p . tramp-sh-handle-file-ownership-preserved-p)
(file-newer-than-file-p . tramp-handle-file-newer-than-file-p) (file-newer-than-file-p . tramp-sh-handle-file-newer-than-file-p)
(file-attributes . tramp-handle-file-attributes) (file-attributes . tramp-sh-handle-file-attributes)
(file-modes . tramp-handle-file-modes) (file-modes . tramp-handle-file-modes)
(directory-files . tramp-handle-directory-files) (directory-files . tramp-handle-directory-files)
(directory-files-and-attributes . tramp-handle-directory-files-and-attributes) (directory-files-and-attributes
(file-name-all-completions . tramp-handle-file-name-all-completions) . tramp-sh-handle-directory-files-and-attributes)
(file-name-all-completions . tramp-sh-handle-file-name-all-completions)
(file-name-completion . tramp-handle-file-name-completion) (file-name-completion . tramp-handle-file-name-completion)
(add-name-to-file . tramp-handle-add-name-to-file) (add-name-to-file . tramp-sh-handle-add-name-to-file)
(copy-file . tramp-handle-copy-file) (copy-file . tramp-sh-handle-copy-file)
(copy-directory . tramp-handle-copy-directory) (copy-directory . tramp-sh-handle-copy-directory)
(rename-file . tramp-handle-rename-file) (rename-file . tramp-sh-handle-rename-file)
(set-file-modes . tramp-handle-set-file-modes) (set-file-modes . tramp-sh-handle-set-file-modes)
(set-file-times . tramp-handle-set-file-times) (set-file-times . tramp-sh-handle-set-file-times)
(make-directory . tramp-handle-make-directory) (make-directory . tramp-sh-handle-make-directory)
(delete-directory . tramp-handle-delete-directory) (delete-directory . tramp-sh-handle-delete-directory)
(delete-file . tramp-handle-delete-file) (delete-file . tramp-sh-handle-delete-file)
(directory-file-name . tramp-handle-directory-file-name) (directory-file-name . tramp-handle-directory-file-name)
;; `executable-find' is not official yet. ;; `executable-find' is not official yet.
(executable-find . tramp-handle-executable-find) (executable-find . tramp-sh-handle-executable-find)
(start-file-process . tramp-handle-start-file-process) (start-file-process . tramp-sh-handle-start-file-process)
(process-file . tramp-handle-process-file) (process-file . tramp-sh-handle-process-file)
(shell-command . tramp-handle-shell-command) (shell-command . tramp-sh-handle-shell-command)
(insert-directory . tramp-handle-insert-directory) (insert-directory . tramp-sh-handle-insert-directory)
(expand-file-name . tramp-handle-expand-file-name) (expand-file-name . tramp-sh-handle-expand-file-name)
(substitute-in-file-name . tramp-handle-substitute-in-file-name) (substitute-in-file-name . tramp-handle-substitute-in-file-name)
(file-local-copy . tramp-handle-file-local-copy) (file-local-copy . tramp-sh-handle-file-local-copy)
(file-remote-p . tramp-handle-file-remote-p) (file-remote-p . tramp-handle-file-remote-p)
(insert-file-contents . tramp-handle-insert-file-contents) (insert-file-contents . tramp-handle-insert-file-contents)
(insert-file-contents-literally (insert-file-contents-literally
. tramp-handle-insert-file-contents-literally) . tramp-sh-handle-insert-file-contents-literally)
(write-region . tramp-handle-write-region) (write-region . tramp-sh-handle-write-region)
(find-backup-file-name . tramp-handle-find-backup-file-name) (find-backup-file-name . tramp-sh-handle-find-backup-file-name)
(make-auto-save-file-name . tramp-handle-make-auto-save-file-name) (make-auto-save-file-name . tramp-sh-handle-make-auto-save-file-name)
(unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory) (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory)
(dired-compress-file . tramp-handle-dired-compress-file) (dired-compress-file . tramp-sh-handle-dired-compress-file)
(dired-recursive-delete-directory (dired-recursive-delete-directory
. tramp-handle-dired-recursive-delete-directory) . tramp-sh-handle-dired-recursive-delete-directory)
(dired-uncache . tramp-handle-dired-uncache) (dired-uncache . tramp-handle-dired-uncache)
(set-visited-file-modtime . tramp-handle-set-visited-file-modtime) (set-visited-file-modtime . tramp-sh-handle-set-visited-file-modtime)
(verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime) (verify-visited-file-modtime . tramp-sh-handle-verify-visited-file-modtime)
(file-selinux-context . tramp-handle-file-selinux-context) (file-selinux-context . tramp-sh-handle-file-selinux-context)
(set-file-selinux-context . tramp-handle-set-file-selinux-context) (set-file-selinux-context . tramp-sh-handle-set-file-selinux-context)
(vc-registered . tramp-handle-vc-registered)) (vc-registered . tramp-sh-handle-vc-registered))
"Alist of handler functions. "Alist of handler functions.
Operations not mentioned here will be handled by the normal Emacs functions.") Operations not mentioned here will be handled by the normal Emacs functions.")
...@@ -933,7 +934,7 @@ Operations not mentioned here will be handled by the normal Emacs functions.") ...@@ -933,7 +934,7 @@ Operations not mentioned here will be handled by the normal Emacs functions.")
;;; File Name Handler Functions: ;;; File Name Handler Functions:
(defun tramp-handle-make-symbolic-link (defun tramp-sh-handle-make-symbolic-link
(filename linkname &optional ok-if-already-exists) (filename linkname &optional ok-if-already-exists)
"Like `make-symbolic-link' for Tramp files. "Like `make-symbolic-link' for Tramp files.
If LINKNAME is a non-Tramp file, it is used verbatim as the target of If LINKNAME is a non-Tramp file, it is used verbatim as the target of
...@@ -988,71 +989,7 @@ target of the symlink differ." ...@@ -988,71 +989,7 @@ target of the symlink differ."
(tramp-shell-quote-argument l-localname)) (tramp-shell-quote-argument l-localname))
t)))) t))))
(defun tramp-handle-load (file &optional noerror nomessage nosuffix must-suffix) (defun tramp-sh-handle-file-truename (filename &optional counter prev-dirs)
"Like `load' for Tramp files."
(with-parsed-tramp-file-name (expand-file-name file) nil
(unless nosuffix
(cond ((file-exists-p (concat file ".elc"))
(setq file (concat file ".elc")))
((file-exists-p (concat file ".el"))
(setq file (concat file ".el")))))
(when must-suffix
;; The first condition is always true for absolute file names.
;; Included for safety's sake.
(unless (or (file-name-directory file)
(string-match "\\.elc?\\'" file))
(tramp-error
v 'file-error
"File `%s' does not include a `.el' or `.elc' suffix" file)))
(unless noerror
(when (not (file-exists-p file))
(tramp-error v 'file-error "Cannot load nonexistent file `%s'" file)))
(if (not (file-exists-p file))
nil
(let ((tramp-message-show-message (not nomessage)))
(with-progress-reporter v 0 (format "Loading %s" file)
(let ((local-copy (file-local-copy file)))
;; MUST-SUFFIX doesn't exist on XEmacs, so let it default to nil.
(unwind-protect
(load local-copy noerror t t)
(delete-file local-copy)))))
t)))
;; Localname manipulation functions that grok Tramp localnames...
(defun tramp-handle-file-name-as-directory (file)
"Like `file-name-as-directory' but aware of Tramp files."
;; `file-name-as-directory' would be sufficient except localname is
;; the empty string.
(let ((v (tramp-dissect-file-name file t)))
;; Run the command on the localname portion only.
(tramp-make-tramp-file-name
(tramp-file-name-method v)
(tramp-file-name-user v)
(tramp-file-name-host v)
(tramp-run-real-handler
'file-name-as-directory (list (or (tramp-file-name-localname v) ""))))))
(defun tramp-handle-file-name-directory (file)
"Like `file-name-directory' but aware of Tramp files."
;; Everything except the last filename thing is the directory. We
;; cannot apply `with-parsed-tramp-file-name', because this expands
;; the remote file name parts. This is a problem when we are in
;; file name completion.
(let ((v (tramp-dissect-file-name file t)))
;; Run the command on the localname portion only.
(tramp-make-tramp-file-name
(tramp-file-name-method v)
(tramp-file-name-user v)
(tramp-file-name-host v)
(tramp-run-real-handler
'file-name-directory (list (or (tramp-file-name-localname v) ""))))))
(defun tramp-handle-file-name-nondirectory (file)
"Like `file-name-nondirectory' but aware of Tramp files."
(with-parsed-tramp-file-name file nil
(tramp-run-real-handler 'file-name-nondirectory (list localname))))
(defun tramp-handle-file-truename (filename &optional counter prev-dirs)
"Like `file-truename' for Tramp files." "Like `file-truename' for Tramp files."
(with-parsed-tramp-file-name (expand-file-name filename) nil (with-parsed-tramp-file-name (expand-file-name filename) nil
(with-file-property v localname "file-truename" (with-file-property v localname "file-truename"
...@@ -1158,7 +1095,7 @@ target of the symlink differ." ...@@ -1158,7 +1095,7 @@ target of the symlink differ."
;; Basic functions. ;; Basic functions.
(defun tramp-handle-file-exists-p (filename) (defun tramp-sh-handle-file-exists-p (filename)
"Like `file-exists-p' for Tramp files." "Like `file-exists-p' for Tramp files."
(with-parsed-tramp-file-name filename nil (with-parsed-tramp-file-name filename nil
(with-file-property v localname "file-exists-p" (with-file-property v localname "file-exists-p"
...@@ -1176,7 +1113,7 @@ target of the symlink differ." ...@@ -1176,7 +1113,7 @@ target of the symlink differ."
;; CCC: This should check for an error condition and signal failure ;; CCC: This should check for an error condition and signal failure
;; when something goes wrong. ;; when something goes wrong.
;; Daniel Pittman <daniel@danann.net> ;; Daniel Pittman <daniel@danann.net>
(defun tramp-handle-file-attributes (filename &optional id-format) (defun tramp-sh-handle-file-attributes (filename &optional id-format)
"Like `file-attributes' for Tramp files." "Like `file-attributes' for Tramp files."
(unless id-format (setq id-format 'integer)) (unless id-format (setq id-format 'integer))
;; Don't modify `last-coding-system-used' by accident. ;; Don't modify `last-coding-system-used' by accident.
...@@ -1314,7 +1251,7 @@ target of the symlink differ." ...@@ -1314,7 +1251,7 @@ target of the symlink differ."
(if (eq id-format 'integer) "%g" "\"%G\"") (if (eq id-format 'integer) "%g" "\"%G\"")
(tramp-shell-quote-argument localname)))) (tramp-shell-quote-argument localname))))
(defun tramp-handle-set-visited-file-modtime (&optional time-list) (defun tramp-sh-handle-set-visited-file-modtime (&optional time-list)
"Like `set-visited-file-modtime' for Tramp files." "Like `set-visited-file-modtime' for Tramp files."
(unless (buffer-file-name) (unless (buffer-file-name)
(error "Can't set-visited-file-modtime: buffer `%s' not visiting a file" (error "Can't set-visited-file-modtime: buffer `%s' not visiting a file"
...@@ -1348,8 +1285,8 @@ target of the symlink differ." ...@@ -1348,8 +1285,8 @@ target of the symlink differ."
nil))))) nil)))))
;; This function makes the same assumption as ;; This function makes the same assumption as
;; `tramp-handle-set-visited-file-modtime'. ;; `tramp-sh-handle-set-visited-file-modtime'.
(defun tramp-handle-verify-visited-file-modtime (buf) (defun tramp-sh-handle-verify-visited-file-modtime (buf)
"Like `verify-visited-file-modtime' for Tramp files. "Like `verify-visited-file-modtime' for Tramp files.
At the time `verify-visited-file-modtime' calls this function, we At the time `verify-visited-file-modtime' calls this function, we
already know that the buffer is visiting a file and that already know that the buffer is visiting a file and that
...@@ -1401,7 +1338,7 @@ of." ...@@ -1401,7 +1338,7 @@ of."
;; only if that agrees with the buffer's record. ;; only if that agrees with the buffer's record.
(t (equal mt '(-1 65535)))))))))) (t (equal mt '(-1 65535))))))))))
(defun tramp-handle-set-file-modes (filename mode) (defun tramp-sh-handle-set-file-modes (filename mode)
"Like `set-file-modes' for Tramp files." "Like `set-file-modes' for Tramp files."
(with-parsed-tramp-file-name filename nil (with-parsed-tramp-file-name filename nil
(tramp-flush-file-property v localname) (tramp-flush-file-property v localname)
...@@ -1413,7 +1350,7 @@ of." ...@@ -1413,7 +1350,7 @@ of."
(tramp-shell-quote-argument localname)) (tramp-shell-quote-argument localname))
"Error while changing file's mode %s" filename))) "Error while changing file's mode %s" filename)))
(defun tramp-handle-set-file-times (filename &optional time) (defun tramp-sh-handle-set-file-times (filename &optional time)
"Like `set-file-times' for Tramp files." "Like `set-file-times' for Tramp files."
(if (file-remote-p filename) (if (file-remote-p filename)
(with-parsed-tramp-file-name filename nil (with-parsed-tramp-file-name filename nil
...@@ -1486,7 +1423,7 @@ and gid of the corresponding user is taken. Both parameters must be integers." ...@@ -1486,7 +1423,7 @@ and gid of the corresponding user is taken. Both parameters must be integers."
vec (format "echo \\\"`%S`\\\"" result)) vec (format "echo \\\"`%S`\\\"" result))
"Enforcing"))))) "Enforcing")))))
(defun tramp-handle-file-selinux-context (filename) (defun tramp-sh-handle-file-selinux-context (filename)
"Like `file-selinux-context' for Tramp files." "Like `file-selinux-context' for Tramp files."
(with-parsed-tramp-file-name filename nil (with-parsed-tramp-file-name filename nil
(with-file-property v localname "file-selinux-context" (with-file-property v localname "file-selinux-context"
...@@ -1507,7 +1444,7 @@ and gid of the corresponding user is taken. Both parameters must be integers." ...@@ -1507,7 +1444,7 @@ and gid of the corresponding user is taken. Both parameters must be integers."
;; Return the context. ;; Return the context.
context)))) context))))
(defun tramp-handle-set-file-selinux-context (filename context) (defun tramp-sh-handle-set-file-selinux-context (filename context)
"Like `set-file-selinux-context' for Tramp files." "Like `set-file-selinux-context' for Tramp files."
(with-parsed-tramp-file-name filename nil (with-parsed-tramp-file-name filename nil
(if (and (consp context) (if (and (consp context)
...@@ -1530,7 +1467,7 @@ and gid of the corresponding user is taken. Both parameters must be integers." ...@@ -1530,7 +1467,7 @@ and gid of the corresponding user is taken. Both parameters must be integers."
;; Simple functions using the `test' command. ;; Simple functions using the `test' command.
(defun tramp-handle-file-executable-p (filename) (defun tramp-sh-handle-file-executable-p (filename)
"Like `file-executable-p' for Tramp files." "Like `file-executable-p' for Tramp files."
(with-parsed-tramp-file-name filename nil (with-parsed-tramp-file-name filename nil
(with-file-property v localname "file-executable-p" (with-file-property v localname "file-executable-p"
...@@ -1539,7 +1476,7 @@ and gid of the corresponding user is taken. Both parameters must be integers." ...@@ -1539,7 +1476,7 @@ and gid of the corresponding user is taken. Both parameters must be integers."
(or (tramp-check-cached-permissions v ?x) (or (tramp-check-cached-permissions v ?x)
(tramp-run-test "-x" filename))))) (tramp-run-test "-x" filename)))))
(defun tramp-handle-file-readable-p (filename) (defun tramp-sh-handle-file-readable-p (filename)
"Like `file-readable-p' for Tramp files." "Like `file-readable-p' for Tramp files."
(with-parsed-tramp-file-name filename nil (with-parsed-tramp-file-name filename nil
(with-file-property v localname "file-readable-p" (with-file-property v localname "file-readable-p"
...@@ -1553,7 +1490,7 @@ and gid of the corresponding user is taken. Both parameters must be integers." ...@@ -1553,7 +1490,7 @@ and gid of the corresponding user is taken. Both parameters must be integers."
;; expansion will also provide a `test' command which groks `-nt' (for ;; expansion will also provide a `test' command which groks `-nt' (for
;; newer than). If this breaks, tell me about it and I'll try to do ;; newer than). If this breaks, tell me about it and I'll try to do
;; something smarter about it. ;; something smarter about it.
(defun tramp-handle-file-newer-than-file-p (file1 file2) (defun tramp-sh-handle-file-newer-than-file-p (file1 file2)
"Like `file-newer-than-file-p' for Tramp files." "Like `file-newer-than-file-p' for Tramp files."
(cond ((not (file-exists-p file1)) (cond ((not (file-exists-p file1))
nil) nil)
...@@ -1588,13 +1525,7 @@ and gid of the corresponding user is taken. Both parameters must be integers." ...@@ -1588,13 +1525,7 @@ and gid of the corresponding user is taken. Both parameters must be integers."
;; Functions implemented using the basic functions above. ;; Functions implemented using the basic functions above.
(defun tramp-handle-file-modes (filename) (defun tramp-sh-handle-file-directory-p (filename)
"Like `file-modes' for Tramp files."
(let ((truename (or (file-truename filename) filename)))
(when (file-exists-p truename)
(tramp-mode-string-to-int (nth 8 (file-attributes truename))))))
(defun tramp-handle-file-directory-p (filename)
"Like `file-directory-p' for Tramp files." "Like `file-directory-p' for Tramp files."
;; Care must be taken that this function returns `t' for symlinks ;; Care must be taken that this function returns `t' for symlinks
;; pointing to directories. Surely the most obvious implementation ;; pointing to directories. Surely the most obvious implementation
...@@ -1608,23 +1539,7 @@ and gid of the corresponding user is taken. Both parameters must be integers." ...@@ -1608,23 +1539,7 @@ and gid of the corresponding user is taken. Both parameters must be integers."
(with-file-property v localname "file-directory-p" (with-file-property v localname "file-directory-p"
(tramp-run-test "-d" filename)))) (tramp-run-test "-d" filename))))
(defun tramp-handle-file-regular-p (filename) (defun tramp-sh-handle-file-writable-p (filename)
"Like `file-regular-p' for Tramp files."
(and (file-exists-p filename)
(eq ?- (aref (nth 8 (file-attributes filename)) 0))))
(defun tramp-handle-file-symlink-p (filename)
"Like `file-symlink-p' for Tramp files."
(with-parsed-tramp-file-name filename nil
(let ((x (car (file-attributes filename))))
(when (stringp x)
;; When Tramp is running on VMS, then `file-name-absolute-p'
;; might do weird things.
(if (file-name-absolute-p x)
(tramp-make-tramp-file-name method user host x)
x)))))
(defun tramp-handle-file-writable-p (filename)
"Like `file-writable-p' for Tramp files." "Like `file-writable-p' for Tramp files."
(with-parsed-tramp-file-name filename nil (with-parsed-tramp-file-name filename nil
(with-file-property v localname "file-writable-p" (with-file-property v localname "file-writable-p"
...@@ -1637,7 +1552,7 @@ and gid of the corresponding user is taken. Both parameters must be integers." ...@@ -1637,7 +1552,7 @@ and gid of the corresponding user is taken. Both parameters must be integers."
(and (tramp-run-test "-d" (file-name-directory filename)) (and (tramp-run-test "-d" (file-name-directory filename))
(tramp-run-test "-w" (file-name-directory filename))))))) (tramp-run-test "-w" (file-name-directory filename)))))))
(defun tramp-handle-file-ownership-preserved-p (filename) (defun tramp-sh-handle-file-ownership-preserved-p (filename)
"Like `file-ownership-preserved-p' for Tramp files." "Like `file-ownership-preserved-p' for Tramp files."
(with-parsed-tramp-file-name filename nil (with-parsed-tramp-file-name filename nil
(with-file-property v localname "file-ownership-preserved-p" (with-file-property v localname "file-ownership-preserved-p"
...@@ -1647,45 +1562,9 @@ and gid of the corresponding user is taken. Both parameters must be integers." ...@@ -1647,45 +1562,9 @@ and gid of the corresponding user is taken. Both parameters must be integers."
(or (null attributes) (or (null attributes)
(= (nth 2 attributes) (tramp-get-remote-uid v 'integer))))))) (= (nth 2 attributes) (tramp-get-remote-uid v 'integer)))))))
;; Other file name ops.
(defun tramp-handle-directory-file-name (directory)
"Like `directory-file-name' for Tramp files."
;; If localname component of filename is "/", leave it unchanged.
;; Otherwise, remove any trailing slash from localname component.
;; Method, host, etc, are unchanged. Does it make sense to try
;; to avoid parsing the filename?
(with-parsed-tramp-file-name directory nil
(if (and (not (zerop (length localname)))
(eq (aref localname (1- (length localname))) ?/)
(not (string= localname "/")))
(substring directory 0 -1)
directory)))
;; Directory listings. ;; Directory listings.
(defun tramp-handle-directory-files (defun tramp-sh-handle-directory-files-and-attributes
(directory &optional full match nosort files-only)
"Like `directory-files' for Tramp files."
;; FILES-ONLY is valid for XEmacs only.
(when (file-directory-p directory)
(setq directory (file-name-as-directory (expand-file-name directory)))
(let ((temp (nreverse (file-name-all-completions "" directory)))
result item)
(while temp
(setq item (directory-file-name (pop temp)))
(when (and (or (null match) (string-match match item))
(or (null files-only)
;; Files only.
(and (equal files-only t) (file-regular-p item))
;; Directories only.
(file-directory-p item)))
(push (if full (concat directory item) item)
result)))
(if nosort result (sort result 'string<)))))
(defun tramp-handle-directory-files-and-attributes
(directory &optional full match nosort id-format) (directory &optional full match nosort id-format)
"Like `directory-files-and-attributes' for Tramp files." "Like `directory-files-and-attributes' for Tramp files."
(unless id-format (setq id-format 'integer)) (unless id-format (setq id-format 'integer))
...@@ -1760,7 +1639,7 @@ and gid of the corresponding user is taken. Both parameters must be integers." ...@@ -1760,7 +1639,7 @@ and gid of the corresponding user is taken. Both parameters must be integers."
;; This function should return "foo/" for directories and "bar" for ;; This function should return "foo/" for directories and "bar" for
;; files. ;; files.
(defun tramp-handle-file-name-all-completions (filename directory) (defun tramp-sh-handle-file-name-all-completions (filename directory)
"Like `file-name-all-completions' for Tramp files." "Like `file-name-all-completions' for Tramp files."
(unless (save-match-data (string-match "/" filename)) (unless (save-match-data (string-match "/" filename))
(with-parsed-tramp-file-name (expand-file-name directory) nil (with-parsed-tramp-file-name (expand-file-name directory) nil
...@@ -1866,7 +1745,7 @@ and gid of the corresponding user is taken. Both parameters must be integers." ...@@ -1866,7 +1745,7 @@ and gid of the corresponding user is taken. Both parameters must be integers."
(forward-line -1) (forward-line -1)
(tramp-error (tramp-error
v 'file-error v 'file-error
"tramp-handle-file-name-all-completions: %s" "tramp-sh-handle-file-name-all-completions: %s"
(buffer-substring (buffer-substring
(point) (tramp-compat-line-end-position)))) (point) (tramp-compat-line-end-position))))
;; For peace of mind, if buffer doesn't end in `fail' ;; For peace of mind, if buffer doesn't end in `fail'
...@@ -1877,7 +1756,7 @@ and gid of the corresponding user is taken. Both parameters must be integers." ...@@ -1877,7 +1756,7 @@ and gid of the corresponding user is taken. Both parameters must be integers."
(tramp-error (tramp-error
v 'file-error v 'file-error
"\ "\
tramp-handle-file-name-all-completions: internal error accessing `%s': `%s'" tramp-sh-handle-file-name-all-completions: internal error accessing `%s': `%s'"
(tramp-shell-quote-argument localname) (buffer-string)))) (tramp-shell-quote-argument localname) (buffer-string))))
(while (zerop (forward-line -1)) (while (zerop (forward-line -1))
...@@ -1903,22 +1782,9 @@ tramp-handle-file-name-all-completions: internal error accessing `%s': `%s'" ...@@ -1903,22 +1782,9 @@ tramp-handle-file-name-all-completions: internal error accessing `%s': `%s'"
"file-name-all-completions" "file-name-all-completions"
result)))))))) result))))))))
(defun tramp-handle-file-name-completion
(filename directory &optional predicate)
"Like `file-name-completion' for Tramp files."
(unless (tramp-tramp-file-p directory)
(error
"tramp-handle-file-name-completion invoked on non-tramp directory `%s'"
directory))
(try-completion
filename
(mapcar 'list (file-name-all-completions filename directory))
(when predicate
(lambda (x) (funcall predicate (expand-file-name (car x) directory))))))
;; cp, mv and ln ;; cp, mv and ln
(defun tramp-handle-add-name-to-file (defun tramp-sh-handle-add-name-to-file
(filename newname &optional ok-if-already-exists) (filename newname &optional ok-if-already-exists)
"Like `add-name-to-file' for Tramp files." "Like `add-name-to-file' for Tramp files."
(unless (tramp-equal-remote filename newname) (unless (tramp-equal-remote filename newname)
...@@ -1950,7 +1816,7 @@ tramp-handle-file-name-all-completions: internal error accessing `%s': `%s'" ...@@ -1950,7 +1816,7 @@ tramp-handle-file-name-all-completions: internal error accessing `%s': `%s'"
"error with add-name-to-file, see buffer `%s' for details" "error with add-name-to-file, see buffer `%s' for details"
(buffer-name)))))) (buffer-name))))))
(defun tramp-handle-copy-file (defun tramp-sh-handle-copy-file
(filename newname &optional ok-if-already-exists keep-date (filename newname &optional ok-if-already-exists keep-date
preserve-uid-gid preserve-selinux-context) preserve-uid-gid preserve-selinux-context)
"Like `copy-file' for Tramp files." "Like `copy-file' for Tramp files."
...@@ -1977,7 +1843,8 @@ tramp-handle-file-name-all-completions: internal error accessing `%s': `%s'" ...@@ -1977,7 +1843,8 @@ tramp-handle-file-name-all-completions: internal error accessing `%s': `%s'"
(tramp-run-real-handler (tramp-run-real-handler
'copy-file (list filename newname ok-if-already-exists keep-date))))) 'copy-file (list filename newname ok-if-already-exists keep-date)))))
(defun tramp-handle-copy-directory (dirname newname &optional keep-date parents) (defun tramp-sh-handle-copy-directory
(dirname newname &optional keep-date parents)
"Like `copy-directory' for Tramp files." "Like `copy-directory' for Tramp files."
(let ((t1 (tramp-tramp-file-p dirname)) (let ((t1 (tramp-tramp-file-p dirname))
(t2 (tramp-tramp-file-p newname))) (t2 (tramp-tramp-file-p newname)))
...@@ -2013,7 +1880,7 @@ tramp-handle-file-name-all-completions: internal error accessing `%s': `%s'" ...@@ -2013,7 +1880,7 @@ tramp-handle-file-name-all-completions: internal error accessing `%s': `%s'"
(tramp-flush-file-property v (file-name-directory localname)) (tramp-flush-file-property v (file-name-directory localname))
(tramp-flush-file-property v localname)))))) (tramp-flush-file-property v localname))))))
(defun tramp-handle-rename-file (defun tramp-sh-handle-rename-file
(filename newname &optional ok-if-already-exists) (filename newname &optional ok-if-already-exists)
"Like `rename-file' for Tramp files." "Like `rename-file' for Tramp files."
;; Check if both files are local -- invoke normal rename-file. ;; Check if both files are local -- invoke normal rename-file.
...@@ -2041,9 +1908,10 @@ as FILENAME. PRESERVE-UID-GID, when non-nil, instructs to keep ...@@ -2041,9 +1908,10 @@ as FILENAME. PRESERVE-UID-GID, when non-nil, instructs to keep
the uid and gid if both files are on the same host. the uid and gid if both files are on the same host.
PRESERVE-SELINUX-CONTEXT activates selinux commands. PRESERVE-SELINUX-CONTEXT activates selinux commands.
This function is invoked by `tramp-handle-copy-file' and This function is invoked by `tramp-sh-handle-copy-file' and
`tramp-handle-rename-file'. It is an error if OP is neither of `copy'