Function: tramp-adb-handle-rename-file

tramp-adb-handle-rename-file is a byte-compiled function defined in tramp-adb.el.gz.

Signature

(tramp-adb-handle-rename-file FILENAME NEWNAME &optional OK-IF-ALREADY-EXISTS)

Documentation

Like rename-file for Tramp files.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp-adb.el.gz
(defun tramp-adb-handle-rename-file
  (filename newname &optional ok-if-already-exists)
  "Like `rename-file' for Tramp files."
  (setq filename (expand-file-name filename)
	newname (expand-file-name newname))

  (if (file-directory-p filename)
      (progn
	(copy-directory filename newname t t)
	(delete-directory filename 'recursive))

    (let ((t1 (tramp-tramp-file-p filename))
	  (t2 (tramp-tramp-file-p newname))
	  ;; We don't want the target file to be compressed, so we
	  ;; let-bind `jka-compr-inhibit' to t.
	  (jka-compr-inhibit t))
      (with-parsed-tramp-file-name (if t1 filename newname) nil
	(unless (file-exists-p filename)
	  (tramp-compat-file-missing v filename))
	(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))

	(with-tramp-progress-reporter
	    v 0 (format "Renaming %s to %s" filename newname)
	  (if (and t1 t2
		   (tramp-equal-remote filename newname)
		   (not (file-directory-p filename)))
	      (let ((l1 (tramp-file-local-name filename))
		    (l2 (tramp-file-local-name newname)))
		;; We must also flush the cache of the directory, because
		;; `file-attributes' reads the values from there.
		(tramp-flush-file-properties v l1)
		(tramp-flush-file-properties v l2)
		;; Short track.
		(tramp-adb-barf-unless-okay
		 v (format
		    "mv -f %s %s"
		    (tramp-shell-quote-argument l1)
		    (tramp-shell-quote-argument l2))
		 "Error renaming %s to %s" filename newname))

	    ;; Rename by copy.
	    (copy-file
	     filename newname ok-if-already-exists 'keep-time 'preserve-uid-gid)
	    (delete-file filename)))))))