- (apply 'ange-ftp-hook-function operation args))
- ;; Normally, the handlers must be discarded
- (t (let* ((inhibit-file-name-handlers
- (list 'tramp-file-name-handler
- 'tramp-completion-file-name-handler
- (and (eq inhibit-file-name-operation operation)
- inhibit-file-name-handlers)))
- (inhibit-file-name-operation operation))
- (apply 'ange-ftp-hook-function operation args)))))))
+ (if (apply 'ange-ftp-hook-function operation args)
+ (let ((v (tramp-dissect-file-name (car args) t)))
+ (aset v 0 tramp-ftp-method)
+ (tramp-set-connection-property v "started" t))
+ nil))
+
+ ;; If the second argument of `copy-file' or `rename-file' is a
+ ;; remote file name but via FTP, ange-ftp doesn't check this.
+ ;; We must copy it locally first, because there is no place in
+ ;; ange-ftp for correct handling.
+ ((and (memq operation '(copy-file rename-file))
+ (file-remote-p (cadr args))
+ (not (tramp-ftp-file-name-p (cadr args))))
+ (let* ((filename (car args))
+ (newname (cadr args))
+ (tmpfile (tramp-compat-make-temp-file filename))
+ (args (cddr args)))
+ ;; We must set `ok-if-already-exists' to t in the first
+ ;; step, because the temp file has been created already.
+ (if (eq operation 'copy-file)
+ (apply operation filename tmpfile t (cdr args))
+ (apply operation filename tmpfile t))
+ (unwind-protect
+ (rename-file tmpfile newname (car args))
+ ;; Cleanup.
+ (ignore-errors (delete-file tmpfile)))))
+
+ ;; Normally, the handlers must be discarded.
+ ;; `inhibit-file-name-handlers' isn't sufficient, because the
+ ;; local file name could be in Tramp syntax as well (for
+ ;; example, returning VMS file names like "/DISK$CAM:/AAA").
+ ;; That's why we set also `tramp-mode' to nil.
+ (t (let* (;(tramp-mode nil)
+ (inhibit-file-name-handlers
+ (list 'tramp-file-name-handler
+ 'tramp-completion-file-name-handler
+ (and (eq inhibit-file-name-operation operation)
+ inhibit-file-name-handlers)))
+ (inhibit-file-name-operation operation))
+ (apply 'ange-ftp-hook-function operation args)))))))