Function: org-babel-interpret-file-mode
org-babel-interpret-file-mode is a byte-compiled function defined in
ob-tangle.el.gz.
Signature
(org-babel-interpret-file-mode MODE)
Documentation
Determine the integer representation of a file MODE specification.
The following forms are currently recognized:
- an integer (returned without modification)
- "o755" (chmod style octal)
- "rwxrw-r--" (ls style specification)
- "a=rw,u+x" (chmod style) *
* The interpretation of these forms relies on file-modes-symbolic-to-number,
and uses org-babel-tangle-default-file-mode as the base mode.
Source Code
;; Defined in /usr/src/emacs/lisp/org/ob-tangle.el.gz
(defun org-babel-interpret-file-mode (mode)
"Determine the integer representation of a file MODE specification.
The following forms are currently recognized:
- an integer (returned without modification)
- \"o755\" (chmod style octal)
- \"rwxrw-r--\" (ls style specification)
- \"a=rw,u+x\" (chmod style) *
* The interpretation of these forms relies on `file-modes-symbolic-to-number',
and uses `org-babel-tangle-default-file-mode' as the base mode."
(cond
((integerp mode)
(if (string-match-p "^[0-7][0-7][0-7]$" (format "%o" mode))
mode
(user-error "%1$o is not a valid file mode octal. \
Did you give the decimal value %1$d by mistake?" mode)))
((not (stringp mode))
(error "File mode %S not recognized as a valid format" mode))
((string-match-p "^o0?[0-7][0-7][0-7]$" mode)
(string-to-number (replace-regexp-in-string "^o" "" mode) 8))
((string-match-p "^[ugoa]*\\(?:[+=-][rwxXstugo]*\\)+\\(,[ugoa]*\\(?:[+=-][rwxXstugo]*\\)+\\)*$" mode)
;; Match regexp taken from `file-modes-symbolic-to-number'.
(file-modes-symbolic-to-number mode org-babel-tangle-default-file-mode))
((string-match-p "^[r-][w-][xs-][r-][w-][xs-][r-][w-][x-]$" mode)
(file-modes-symbolic-to-number (concat "u=" (delete ?- (substring mode 0 3))
",g=" (delete ?- (substring mode 3 6))
",o=" (delete ?- (substring mode 6 9)))
0))
(t (error "File mode %S not recognized as a valid format. See `org-babel-interpret-file-mode'" mode))))