Function: dired-do-chxxx

dired-do-chxxx is a byte-compiled function defined in dired-aux.el.gz.

Signature

(dired-do-chxxx ATTRIBUTE-NAME PROGRAM OP-SYMBOL ARG)

Source Code

;; Defined in /usr/src/emacs/lisp/dired-aux.el.gz
;;; Change file attributes

(defun dired-do-chxxx (attribute-name program op-symbol arg)
  ;; Change file attributes (group, owner, timestamp) of marked files and
  ;; refresh their file lines.
  ;; ATTRIBUTE-NAME is a string describing the attribute to the user.
  ;; PROGRAM is the program used to change the attribute.
  ;; OP-SYMBOL is the type of operation (for use in `dired-mark-pop-up').
  ;; ARG describes which files to use, as in `dired-get-marked-files'.
  (let* ((files (dired-get-marked-files t arg nil nil t))
	 ;; The source of default file attributes is the file at point.
	 (default-file (dired-get-filename t t))
	 (default (when default-file
		    (cond ((eq op-symbol 'touch)
			   (format-time-string
			    "%Y%m%d%H%M.%S"
			    (file-attribute-modification-time
			     (file-attributes default-file))))
			  ((eq op-symbol 'chown)
			   (file-attribute-user-id
			    (file-attributes default-file 'string)))
			  ((eq op-symbol 'chgrp)
			   (file-attribute-group-id
			    (file-attributes default-file 'string))))))
         (prompt (format-prompt "Change %s of %%s to"
                                (when (eq op-symbol 'touch)
                                    "now")
                                attribute-name))
	 (new-attribute (dired-mark-read-string prompt nil op-symbol
						arg files default
						(cond ((eq op-symbol 'chown)
						       (system-users))
						      ((eq op-symbol 'chgrp)
						       (system-groups)))))
	 (operation (concat program " " new-attribute))
         ;; When file-name-coding-system is set to something different
         ;; from locale-coding-system, leaving the encoding
         ;; determination to call-process will do the wrong thing,
         ;; because the arguments in this case are file names, not
         ;; just some arbitrary text.  (This must be bound last, to
         ;; avoid adverse effects on any of the preceding forms.)
         (coding-system-for-write (or file-name-coding-system
                                      default-file-name-coding-system))
	 failures)
    (setq failures
	  (dired-bunch-files 10000
			     #'dired-check-process
			     (append
			      (list operation program)
			      (unless (or (string-equal new-attribute "")
					  ;; Use `eq' instead of `equal'
					  ;; to detect empty input (bug#12399).
					  (eq new-attribute default))
				(if (eq op-symbol 'touch)
				    (list "-t" new-attribute)
				  (list new-attribute)))
			      (if (string-match-p "gnu" system-configuration)
				  '("--") nil))
			     files))
    (dired-do-redisplay arg);; moves point if ARG is an integer
    (if failures
	(dired-log-summary
	 (format "%s: error" operation)
	 nil)))
  (dired-post-do-command))