Mercurial > emacs
comparison lisp/files.el @ 98838:fe7985b2f625
(trash-directory): Run thru `convert-standard-filename'.
(file-modes-char-to-who, file-modes-char-to-right)
(file-modes-rights-to-number, file-modes-symbolic-to-number)
(read-file-modes): Doc fixes.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Sat, 18 Oct 2008 18:40:25 +0000 |
parents | 56d0534bbfa5 |
children | e152a404d947 |
comparison
equal
deleted
inserted
replaced
98837:19841b2ddd50 | 98838:fe7985b2f625 |
---|---|
5692 (apply operation arguments))))) | 5692 (apply operation arguments))))) |
5693 | 5693 |
5694 ;; Symbolic modes and read-file-modes. | 5694 ;; Symbolic modes and read-file-modes. |
5695 | 5695 |
5696 (defun file-modes-char-to-who (char) | 5696 (defun file-modes-char-to-who (char) |
5697 "Convert CHAR to a who-mask from a symbolic mode notation. | 5697 "Convert CHAR to a numeric bit-mask for extracting mode bits. |
5698 CHAR is in [ugoa] and represents the users on which rights are applied." | 5698 CHAR is in [ugoa] and represents the category of users (Owner, Group, |
5699 Others, or All) for whom to produce the mask. | |
5700 The bit-mask that is returned extracts from mode bits the access rights | |
5701 for the specified category of users." | |
5699 (cond ((= char ?u) #o4700) | 5702 (cond ((= char ?u) #o4700) |
5700 ((= char ?g) #o2070) | 5703 ((= char ?g) #o2070) |
5701 ((= char ?o) #o1007) | 5704 ((= char ?o) #o1007) |
5702 ((= char ?a) #o7777) | 5705 ((= char ?a) #o7777) |
5703 (t (error "%c: bad `who' character" char)))) | 5706 (t (error "%c: bad `who' character" char)))) |
5704 | 5707 |
5705 (defun file-modes-char-to-right (char &optional from) | 5708 (defun file-modes-char-to-right (char &optional from) |
5706 "Convert CHAR to a right-mask from a symbolic mode notation. | 5709 "Convert CHAR to a numeric value of mode bits. |
5707 CHAR is in [rwxXstugo] and represents a right. | 5710 CHAR is in [rwxXstugo] and represents symbolic access permissions. |
5708 If CHAR is in [Xugo], the value is extracted from FROM (or 0 if nil)." | 5711 If CHAR is in [Xugo], the value is taken from FROM (or 0 if omitted)." |
5709 (or from (setq from 0)) | 5712 (or from (setq from 0)) |
5710 (cond ((= char ?r) #o0444) | 5713 (cond ((= char ?r) #o0444) |
5711 ((= char ?w) #o0222) | 5714 ((= char ?w) #o0222) |
5712 ((= char ?x) #o0111) | 5715 ((= char ?x) #o0111) |
5713 ((= char ?s) #o1000) | 5716 ((= char ?s) #o1000) |
5721 ((= char ?o) (let ((oright (logand #o1007 from))) | 5724 ((= char ?o) (let ((oright (logand #o1007 from))) |
5722 (+ oright (* oright #o10) (* oright #o100)))) | 5725 (+ oright (* oright #o10) (* oright #o100)))) |
5723 (t (error "%c: bad right character" char)))) | 5726 (t (error "%c: bad right character" char)))) |
5724 | 5727 |
5725 (defun file-modes-rights-to-number (rights who-mask &optional from) | 5728 (defun file-modes-rights-to-number (rights who-mask &optional from) |
5726 "Convert a right string to a right-mask from a symbolic modes notation. | 5729 "Convert a symbolic mode string specification to an equivalent number. |
5727 RIGHTS is the right string, it should match \"([+=-][rwxXstugo]+)+\". | 5730 RIGHTS is the symbolic mode spec, it should match \"([+=-][rwxXstugo]+)+\". |
5728 WHO-MASK is the mask number of the users on which the rights are to be applied. | 5731 WHO-MASK is the bit-mask specifying the category of users to which to |
5729 FROM (or 0 if nil) is the orginal modes of the file to be chmod'ed." | 5732 apply the access permissions. See `file-modes-char-to-who'. |
5733 FROM (or 0 if nil) gives the mode bits on which to base permissions if | |
5734 RIGHTS request to add, remove, or set permissions based on existing ones, | |
5735 as in \"og+rX-w\"." | |
5730 (let* ((num-rights (or from 0)) | 5736 (let* ((num-rights (or from 0)) |
5731 (list-rights (string-to-list rights)) | 5737 (list-rights (string-to-list rights)) |
5732 (op (pop list-rights))) | 5738 (op (pop list-rights))) |
5733 (while (memq op '(?+ ?- ?=)) | 5739 (while (memq op '(?+ ?- ?=)) |
5734 (let ((num-right 0) | 5740 (let ((num-right 0) |
5750 "Convert symbolic file modes to numeric file modes. | 5756 "Convert symbolic file modes to numeric file modes. |
5751 MODES is the string to convert, it should match | 5757 MODES is the string to convert, it should match |
5752 \"[ugoa]*([+-=][rwxXstugo]+)+,...\". | 5758 \"[ugoa]*([+-=][rwxXstugo]+)+,...\". |
5753 See (info \"(coreutils)File permissions\") for more information on this | 5759 See (info \"(coreutils)File permissions\") for more information on this |
5754 notation. | 5760 notation. |
5755 FROM (or 0 if nil) is the orginal modes of the file to be chmod'ed." | 5761 FROM (or 0 if nil) gives the mode bits on which to base permissions if |
5762 MODES request to add, remove, or set permissions based on existing ones, | |
5763 as in \"og+rX-w\"." | |
5756 (save-match-data | 5764 (save-match-data |
5757 (let ((case-fold-search nil) | 5765 (let ((case-fold-search nil) |
5758 (num-modes (or from 0))) | 5766 (num-modes (or from 0))) |
5759 (while (/= (string-to-char modes) 0) | 5767 (while (/= (string-to-char modes) 0) |
5760 (if (string-match "^\\([ugoa]*\\)\\([+=-][rwxXstugo]+\\)+\\(,\\|\\)" modes) | 5768 (if (string-match "^\\([ugoa]*\\)\\([+=-][rwxXstugo]+\\)+\\(,\\|\\)" modes) |
5769 modes (substring modes (match-end 3)))) | 5777 modes (substring modes (match-end 3)))) |
5770 (error "Parse error in modes near `%s'" (substring modes 0)))) | 5778 (error "Parse error in modes near `%s'" (substring modes 0)))) |
5771 num-modes))) | 5779 num-modes))) |
5772 | 5780 |
5773 (defun read-file-modes (&optional prompt orig-file) | 5781 (defun read-file-modes (&optional prompt orig-file) |
5774 "Read file modes in octal or symbolic notation. | 5782 "Read file modes in octal or symbolic notation and return its numeric value. |
5775 PROMPT is used as the prompt, default to `File modes (octal or symbolic): '. | 5783 PROMPT is used as the prompt, default to `File modes (octal or symbolic): '. |
5776 ORIG-FILE is the original file of which modes will be changed." | 5784 ORIG-FILE is the name of a file on whose mode bits to base returned |
5785 permissions if what user types requests to add, remove, or set permissions | |
5786 based on existing mode bits, as in \"og+rX-w\"." | |
5777 (let* ((modes (or (if orig-file (file-modes orig-file) 0) | 5787 (let* ((modes (or (if orig-file (file-modes orig-file) 0) |
5778 (error "File not found"))) | 5788 (error "File not found"))) |
5779 (modestr (and (stringp orig-file) | 5789 (modestr (and (stringp orig-file) |
5780 (nth 8 (file-attributes orig-file)))) | 5790 (nth 8 (file-attributes orig-file)))) |
5781 (default | 5791 (default |
5793 (if (string-match "^[0-7]+" value) | 5803 (if (string-match "^[0-7]+" value) |
5794 (string-to-number value 8) | 5804 (string-to-number value 8) |
5795 (file-modes-symbolic-to-number value modes))))) | 5805 (file-modes-symbolic-to-number value modes))))) |
5796 | 5806 |
5797 | 5807 |
5798 ;; Trash can handling. | 5808 ;; Trashcan handling. |
5799 (defcustom trash-directory "~/.Trash" | 5809 (defcustom trash-directory (convert-standard-filename "~/.Trash") |
5800 "Directory for `move-file-to-trash' to move files and directories to. | 5810 "Directory for `move-file-to-trash' to move files and directories to. |
5801 This directory is only used when the function `system-move-file-to-trash' is | 5811 This directory is only used when the function `system-move-file-to-trash' is |
5802 not defined. Relative paths are interpreted relative to `default-directory'. | 5812 not defined. Relative paths are interpreted relative to `default-directory'. |
5803 See also `delete-by-moving-to-trash'." | 5813 See also `delete-by-moving-to-trash'." |
5804 :type 'directory | 5814 :type 'directory |