Function: eshell-shuffle-files

eshell-shuffle-files is a byte-compiled function defined in em-unix.el.gz.

Signature

(eshell-shuffle-files COMMAND ACTION FILES TARGET FUNC DEEP &rest ARGS)

Documentation

Shuffle around some filesystem entries, using FUNC to do the work.

Source Code

;; Defined in /usr/src/emacs/lisp/eshell/em-unix.el.gz
(defun eshell-shuffle-files (command action files target func deep &rest args)
  "Shuffle around some filesystem entries, using FUNC to do the work."
  (let ((attr-target (eshell-file-attributes target))
	(is-dir (or (file-directory-p target)
		    (and em-preview (not eshell-warn-dot-directories))))
	attr)
    (if (and (not em-preview) (not is-dir)
	     (> (length files) 1))
	(error "%s: when %s multiple files, last argument must be a directory"
	       command action))
    (while files
      (setcar files (directory-file-name (car files)))
      (cond
       ((string-match "\\`\\.\\.?\\'"
		      (file-name-nondirectory (car files)))
	(if eshell-warn-dot-directories
	    (eshell-error (format "%s: %s: omitting directory\n"
				  command (car files)))))
       ((and attr-target
	     (or (not (eshell-under-windows-p))
		 (eq system-type 'ms-dos))
	     (setq attr (eshell-file-attributes (car files)))
	     (file-attribute-inode-number attr-target)
	     (file-attribute-inode-number attr)
	     (file-attribute-device-number attr-target)
	     (file-attribute-device-number attr)
	     (equal (file-attribute-file-identifier attr-target)
		    (file-attribute-file-identifier attr)))
	(eshell-error (format-message "%s: `%s' and `%s' are the same file\n"
				      command (car files) target)))
       (t
	(let ((source (car files))
	      (target (if is-dir
			  (expand-file-name
			   (file-name-nondirectory (car files)) target)
			target))
	      link)
	  (if (and (file-directory-p source)
		   (or (not no-dereference)
		       (not (file-symlink-p source)))
		   (not (memq func '(make-symbolic-link
				     add-name-to-file))))
	      (if (and (eq func 'copy-file)
		       (not em-recursive))
		  (eshell-error (format "%s: %s: omitting directory\n"
					command (car files)))
		(let (eshell-warn-dot-directories)
		  (if (and (not deep)
			   (eq func 'rename-file)
			   (equal (file-attribute-device-number
				   (eshell-file-attributes
				    (file-name-directory
				     (directory-file-name
				      (expand-file-name source)))))
				  (file-attribute-device-number
				   (eshell-file-attributes
				    (file-name-directory
				     (directory-file-name
				      (expand-file-name target)))))))
		      (apply 'eshell-funcalln func source target args)
		  (unless (file-directory-p target)
		    (if em-verbose
			(eshell-printn
			 (format "%s: making directory %s"
				 command target)))
		    (unless em-preview
		      (eshell-funcalln 'make-directory target)))
		  (apply 'eshell-shuffle-files
			 command action
			 (mapcar
                          (lambda (file)
                            (concat source "/" file))
			  (directory-files source))
			 target func t args)
		  (when (eq func 'rename-file)
		    (if em-verbose
			(eshell-printn
			 (format "%s: deleting directory %s"
				 command source)))
		    (unless em-preview
		      (eshell-funcalln 'delete-directory source))))))
	    (if em-verbose
		(eshell-printn (format "%s: %s -> %s" command
				       source target)))
	    (unless em-preview
	      (if (and no-dereference
		       (setq link (file-symlink-p source)))
		  (progn
		    (apply 'eshell-funcalln 'make-symbolic-link
			   link target
                           ;; `make-symbolic-link' doesn't have
                           ;; KEEP-TIME; just OK-IF-ALREADY-EXISTS.
                           (list (car args)))
		    (if (eq func 'rename-file)
			(if (and (file-directory-p source)
				 (not (file-symlink-p source)))
			    (eshell-funcalln 'delete-directory source)
			  (eshell-funcalln 'delete-file source))))
		(apply 'eshell-funcalln func source target args)))))))
      (setq files (cdr files)))))