+ (cond
+ (preserve-selinux-context
+ (tramp-compat-funcall
+ 'copy-file filename newname ok-if-already-exists keep-date
+ preserve-uid-gid preserve-selinux-context))
+ (preserve-uid-gid
+ (tramp-compat-funcall
+ 'copy-file filename newname ok-if-already-exists keep-date
+ preserve-uid-gid))
+ (t
+ (copy-file filename newname ok-if-already-exists keep-date))))
+
+;; `copy-directory' is a new function in Emacs 23.2. Implementation
+;; is taken from there.
+(defun tramp-compat-copy-directory
+ (directory newname &optional keep-time parents)
+ "Make a copy of DIRECTORY (compat function)."
+ (if (fboundp 'copy-directory)
+ (tramp-compat-funcall 'copy-directory directory newname keep-time parents)
+
+ ;; If `default-directory' is a remote directory, make sure we find
+ ;; its `copy-directory' handler.
+ (let ((handler (or (find-file-name-handler directory 'copy-directory)
+ (find-file-name-handler newname 'copy-directory))))
+ (if handler
+ (funcall handler 'copy-directory directory newname keep-time parents)
+
+ ;; Compute target name.
+ (setq directory (directory-file-name (expand-file-name directory))
+ newname (directory-file-name (expand-file-name newname)))
+ (if (and (file-directory-p newname)
+ (not (string-equal (file-name-nondirectory directory)
+ (file-name-nondirectory newname))))
+ (setq newname
+ (expand-file-name
+ (file-name-nondirectory directory) newname)))
+ (if (not (file-directory-p newname)) (make-directory newname parents))
+
+ ;; Copy recursively.
+ (mapc
+ (lambda (file)
+ (if (file-directory-p file)
+ (tramp-compat-copy-directory file newname keep-time parents)
+ (copy-file file newname t keep-time)))
+ ;; We do not want to delete "." and "..".
+ (directory-files
+ directory 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*"))
+
+ ;; Set directory attributes.
+ (set-file-modes newname (file-modes directory))
+ (if keep-time
+ (set-file-times newname (nth 5 (file-attributes directory))))))))
+
+;; TRASH has been introduced with Emacs 24.1.
+(defun tramp-compat-delete-file (filename &optional trash)
+ "Like `delete-file' for Tramp files (compat function)."
+ (condition-case nil
+ (tramp-compat-funcall 'delete-file filename trash)
+ ;; This Emacs version does not support the TRASH flag.
+ (wrong-number-of-arguments
+ (let ((delete-by-moving-to-trash
+ (and (boundp 'delete-by-moving-to-trash)
+ (symbol-value 'delete-by-moving-to-trash)
+ trash)))
+ (delete-file filename)))))
+
+;; RECURSIVE has been introduced with Emacs 23.2.
+(defun tramp-compat-delete-directory (directory &optional recursive)
+ "Like `delete-directory' for Tramp files (compat function)."
+ (if (null recursive)
+ (delete-directory directory)
+ (condition-case nil
+ (tramp-compat-funcall 'delete-directory directory recursive)
+ ;; This Emacs version does not support the RECURSIVE flag. We
+ ;; use the implementation from Emacs 23.2.
+ (wrong-number-of-arguments
+ (setq directory (directory-file-name (expand-file-name directory)))
+ (if (not (file-symlink-p directory))
+ (mapc (lambda (file)
+ (if (eq t (car (file-attributes file)))
+ (tramp-compat-delete-directory file recursive)
+ (delete-file file)))
+ (directory-files
+ directory 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")))
+ (delete-directory directory)))))
+
+;; `number-sequence' does not exist in XEmacs. Implementation is
+;; taken from Emacs 23.
+(defun tramp-compat-number-sequence (from &optional to inc)
+ "Return a sequence of numbers from FROM to TO as a list (compat function)."
+ (if (or (subrp 'number-sequence) (symbol-file 'number-sequence))
+ (tramp-compat-funcall 'number-sequence from to inc)
+ (if (or (not to) (= from to))
+ (list from)
+ (or inc (setq inc 1))
+ (when (zerop inc) (error "The increment can not be zero"))
+ (let (seq (n 0) (next from))
+ (if (> inc 0)
+ (while (<= next to)
+ (setq seq (cons next seq)
+ n (1+ n)
+ next (+ from (* n inc))))
+ (while (>= next to)
+ (setq seq (cons next seq)
+ n (1+ n)
+ next (+ from (* n inc)))))
+ (nreverse seq)))))
+
+(defun tramp-compat-split-string (string pattern)
+ "Like `split-string' but omit empty strings.
+In Emacs, (split-string \"/foo/bar\" \"/\") returns (\"foo\" \"bar\").
+This is, the first, empty, element is omitted. In XEmacs, the first
+element is not omitted."
+ (delete "" (split-string string pattern)))
+
+(defun tramp-compat-process-running-p (process-name)
+ "Returns `t' if system process PROCESS-NAME is running for `user-login-name'."
+ (when (stringp process-name)
+ (cond
+ ;; GNU Emacs 22 on w32.
+ ((fboundp 'w32-window-exists-p)
+ (tramp-compat-funcall 'w32-window-exists-p process-name process-name))
+
+ ;; GNU Emacs 23.
+ ((and (fboundp 'list-system-processes) (fboundp 'process-attributes))
+ (let (result)
+ (dolist (pid (tramp-compat-funcall 'list-system-processes) result)
+ (let ((attributes (tramp-compat-funcall 'process-attributes pid)))
+ (when (and (string-equal
+ (cdr (assoc 'user attributes)) (user-login-name))
+ (let ((comm (cdr (assoc 'comm attributes))))
+ ;; The returned command name could be truncated
+ ;; to 15 characters. Therefore, we cannot check
+ ;; for `string-equal'.
+ (and comm (string-match
+ (concat "^" (regexp-quote comm))
+ process-name))))
+ (setq result t))))))
+
+ ;; Fallback, if there is no Lisp support yet.
+ (t (let ((default-directory
+ (if (file-remote-p default-directory)
+ (tramp-compat-temporary-file-directory)
+ default-directory))
+ (unix95 (getenv "UNIX95"))
+ result)
+ (setenv "UNIX95" "1")
+ (when (member
+ (user-login-name)
+ (tramp-compat-split-string
+ (shell-command-to-string
+ (format "ps -C %s -o user=" process-name))
+ "[ \f\t\n\r\v]+"))
+ (setq result t))
+ (setenv "UNIX95" unix95)
+ result)))))