Function: tramp-smb-handle-copy-file

tramp-smb-handle-copy-file is a byte-compiled function defined in tramp-smb.el.gz.

Signature

(tramp-smb-handle-copy-file FILENAME NEWNAME &optional OK-IF-ALREADY-EXISTS KEEP-DATE PRESERVE-UID-GID PRESERVE-EXTENDED-ATTRIBUTES)

Documentation

Like copy-file for Tramp files.

KEEP-DATE has no effect in case NEWNAME resides on an SMB server. PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp-smb.el.gz
(defun tramp-smb-handle-copy-file
  (filename newname &optional ok-if-already-exists keep-date
   _preserve-uid-gid _preserve-extended-attributes)
  "Like `copy-file' for Tramp files.
KEEP-DATE has no effect in case NEWNAME resides on an SMB server.
PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
  (setq filename (expand-file-name filename)
	newname (expand-file-name newname))
  (with-tramp-progress-reporter
      (tramp-dissect-file-name
       (if (tramp-tramp-file-p filename) filename newname))
      0 (format "Copying %s to %s" filename newname)

    (if (file-directory-p filename)
	(copy-directory filename newname keep-date 'parents 'copy-contents)

      (unless (file-exists-p filename)
	(tramp-compat-file-missing
	 (tramp-dissect-file-name
	  (if (tramp-tramp-file-p filename) filename newname))
	 filename))

      (if-let ((tmpfile (file-local-copy filename)))
	  ;; Remote filename.
	  (condition-case err
	      (rename-file tmpfile newname ok-if-already-exists)
	    ((error quit)
	     (delete-file tmpfile)
	     (signal (car err) (cdr err))))

	;; Remote newname.
	(when (and (file-directory-p newname)
		   (directory-name-p newname))
	  (setq newname
		(expand-file-name (file-name-nondirectory filename) newname)))

	(with-parsed-tramp-file-name newname nil
	  (when (and (not ok-if-already-exists) (file-exists-p newname))
	    (tramp-error v 'file-already-exists newname))
	  (when (and (file-directory-p newname)
		     (not (directory-name-p newname)))
	    (tramp-error v 'file-error "File is a directory %s" newname))

	  ;; We must also flush the cache of the directory, because
	  ;; `file-attributes' reads the values from there.
	  (tramp-flush-file-properties v localname)
	  (unless (tramp-smb-get-share v)
	    (tramp-error
	     v 'file-error "Target `%s' must contain a share name" newname))
	  (unless (tramp-smb-send-command
		   v (format "put \"%s\" \"%s\""
			     (tramp-compat-file-name-unquote filename)
			     (tramp-smb-get-localname v)))
	    (tramp-error
	     v 'file-error "Cannot copy `%s' to `%s'" filename newname)))))

    ;; KEEP-DATE handling.
    (when keep-date
      (tramp-compat-set-file-times
       newname
       (tramp-compat-file-attribute-modification-time
	(file-attributes filename))
       (unless ok-if-already-exists 'nofollow)))))