Function: tramp-do-copy-or-rename-file-via-buffer
tramp-do-copy-or-rename-file-via-buffer is a byte-compiled function
defined in tramp-sh.el.gz.
Signature
(tramp-do-copy-or-rename-file-via-buffer OP FILENAME NEWNAME OK-IF-ALREADY-EXISTS KEEP-DATE)
Documentation
Use an Emacs buffer to copy or rename a file.
First arg OP is either copy or rename and indicates the operation.
FILENAME is the source file, NEWNAME the target file.
KEEP-DATE is non-nil if NEWNAME should have the same timestamp as FILENAME.
Source Code
;; Defined in /usr/src/emacs/lisp/net/tramp-sh.el.gz
(defun tramp-do-copy-or-rename-file-via-buffer
(op filename newname ok-if-already-exists keep-date)
"Use an Emacs buffer to copy or rename a file.
First arg OP is either `copy' or `rename' and indicates the operation.
FILENAME is the source file, NEWNAME the target file.
KEEP-DATE is non-nil if NEWNAME should have the same timestamp as FILENAME."
;; FILENAME and NEWNAME are already expanded.
;; Check, whether file is too large. Emacs checks in `insert-file-1'
;; and `find-file-noselect', but that's not called here.
(abort-if-file-too-large
(file-attribute-size (file-attributes (file-truename filename)))
(symbol-name op) filename)
;; We must disable multibyte, because binary data shall not be
;; converted. We don't want the target file to be compressed, so we
;; let-bind `jka-compr-inhibit' to t. `epa-file-handler' shall not
;; be called either. We remove `tramp-file-name-handler' from
;; `inhibit-file-name-handlers'; otherwise the file name handler for
;; `insert-file-contents' might be deactivated in some corner cases.
(let ((coding-system-for-read 'binary)
(coding-system-for-write 'binary)
(jka-compr-inhibit t)
(inhibit-file-name-operation 'write-region)
(inhibit-file-name-handlers
(cons 'epa-file-handler
(remq 'tramp-file-name-handler inhibit-file-name-handlers))))
(with-temp-file newname
(set-buffer-multibyte nil)
(insert-file-contents-literally filename)))
;; KEEP-DATE handling.
(when keep-date
(tramp-compat-set-file-times
newname
(file-attribute-modification-time (file-attributes filename))
(unless ok-if-already-exists 'nofollow)))
;; Set the mode.
(set-file-modes newname (tramp-default-file-modes filename))
;; If the operation was `rename', delete the original file.
(unless (eq op 'copy) (delete-file filename)))