diff options
| author | Jim Porter | 2023-03-04 22:11:23 -0800 |
|---|---|---|
| committer | Jim Porter | 2024-01-27 22:21:23 -0800 |
| commit | a3cd284b90edcc7e06b21110cdbf55d11fb6fd0d (patch) | |
| tree | 3fc7c170c6fc0e025f97e0ef136e4aa1e9c68f63 | |
| parent | 236317e5d2284399d6ca0413ea2a29b84270d545 (diff) | |
| download | emacs-a3cd284b90edcc7e06b21110cdbf55d11fb6fd0d.tar.gz emacs-a3cd284b90edcc7e06b21110cdbf55d11fb6fd0d.zip | |
Support setting umask symbolically in Eshell
* lisp/eshell/em-basic.el (eshell/umask): Handle setting umask
symbolically, and make setting umask take precedence over "-S".
* test/lisp/eshell/em-basic-tests.el
(em-basic-test/umask-print-numeric, em-basic-test/umask-read-symbolic,
em-basic-test/umask-set): Rename to...
(em-basic-test/umask/print-numeric)
(em-basic-test/umask/print-symbolic, em-basic-test/umask/set-numeric):
... these.
(em-basic-test/umask/set-symbolic, em-basic-test/umask/set-with-S):
New tests.
* etc/NEWS: Announce this change.
| -rw-r--r-- | etc/NEWS | 8 | ||||
| -rw-r--r-- | lisp/eshell/em-basic.el | 24 | ||||
| -rw-r--r-- | test/lisp/eshell/em-basic-tests.el | 34 |
3 files changed, 52 insertions, 14 deletions
| @@ -678,6 +678,14 @@ command passed as arguments to 'env'. If you pass any initial | |||
| 678 | arguments of the form 'VAR=VALUE', 'env' will first set 'VAR' to | 678 | arguments of the form 'VAR=VALUE', 'env' will first set 'VAR' to |
| 679 | 'VALUE' before running the command. | 679 | 'VALUE' before running the command. |
| 680 | 680 | ||
| 681 | --- | ||
| 682 | *** Eshell's 'umask' command now supports setting the mask symbolically. | ||
| 683 | Now, you can pass an argument like "u+w,o-r" to Eshell's 'umask' | ||
| 684 | command, which will give write permission for owners of newly-created | ||
| 685 | files and deny read permission for users who are not members of the | ||
| 686 | file's group. See the Info node '(coreutils)File permissions' for | ||
| 687 | more information on this notation. | ||
| 688 | |||
| 681 | +++ | 689 | +++ |
| 682 | *** New special reference type '#<marker POSITION BUFFER>'. | 690 | *** New special reference type '#<marker POSITION BUFFER>'. |
| 683 | This special reference type returns a marker at 'POSITION' in | 691 | This special reference type returns a marker at 'POSITION' in |
diff --git a/lisp/eshell/em-basic.el b/lisp/eshell/em-basic.el index 8f68a750bd7..6ec53ef9412 100644 --- a/lisp/eshell/em-basic.el +++ b/lisp/eshell/em-basic.el | |||
| @@ -160,6 +160,18 @@ or `eshell-printn' for display." | |||
| 160 | :preserve-args | 160 | :preserve-args |
| 161 | :usage "[-S] [mode]") | 161 | :usage "[-S] [mode]") |
| 162 | (cond | 162 | (cond |
| 163 | (args | ||
| 164 | (let* ((mask (car args)) | ||
| 165 | (modes | ||
| 166 | (if (stringp mask) | ||
| 167 | (if (string-match (rx bos (+ (any "0-7")) eos) mask) | ||
| 168 | (- #o777 (string-to-number mask 8)) | ||
| 169 | (file-modes-symbolic-to-number | ||
| 170 | mask (default-file-modes))) | ||
| 171 | (- #o777 mask)))) | ||
| 172 | (set-default-file-modes modes) | ||
| 173 | (eshell-print | ||
| 174 | "Warning: umask changed for all new files created by Emacs.\n"))) | ||
| 163 | (symbolic-p | 175 | (symbolic-p |
| 164 | (let ((mode (default-file-modes))) | 176 | (let ((mode (default-file-modes))) |
| 165 | (eshell-printn | 177 | (eshell-printn |
| @@ -173,17 +185,9 @@ or `eshell-printn' for display." | |||
| 173 | (concat (and (= (logand mode 1) 1) "r") | 185 | (concat (and (= (logand mode 1) 1) "r") |
| 174 | (and (= (logand mode 2) 2) "w") | 186 | (and (= (logand mode 2) 2) "w") |
| 175 | (and (= (logand mode 4) 4) "x")))))) | 187 | (and (= (logand mode 4) 4) "x")))))) |
| 176 | ((not args) | ||
| 177 | (eshell-printn (format "%03o" (logand (lognot (default-file-modes)) | ||
| 178 | #o777)))) | ||
| 179 | (t | 188 | (t |
| 180 | (when (stringp (car args)) | 189 | (eshell-printn (format "%03o" (logand (lognot (default-file-modes)) |
| 181 | (if (string-match "^[0-7]+$" (car args)) | 190 | #o777))))) |
| 182 | (setcar args (string-to-number (car args) 8)) | ||
| 183 | (error "Setting umask symbolically is not yet implemented"))) | ||
| 184 | (set-default-file-modes (- #o777 (car args))) | ||
| 185 | (eshell-print | ||
| 186 | "Warning: umask changed for all new files created by Emacs.\n"))) | ||
| 187 | nil)) | 191 | nil)) |
| 188 | 192 | ||
| 189 | (put 'eshell/umask 'eshell-no-numeric-conversions t) | 193 | (put 'eshell/umask 'eshell-no-numeric-conversions t) |
diff --git a/test/lisp/eshell/em-basic-tests.el b/test/lisp/eshell/em-basic-tests.el index 960e04690a5..ebb91cdeea0 100644 --- a/test/lisp/eshell/em-basic-tests.el +++ b/test/lisp/eshell/em-basic-tests.el | |||
| @@ -33,7 +33,7 @@ | |||
| 33 | 33 | ||
| 34 | ;;; Tests: | 34 | ;;; Tests: |
| 35 | 35 | ||
| 36 | (ert-deftest em-basic-test/umask-print-numeric () | 36 | (ert-deftest em-basic-test/umask/print-numeric () |
| 37 | "Test printing umask numerically." | 37 | "Test printing umask numerically." |
| 38 | (cl-letf (((symbol-function 'default-file-modes) (lambda () #o775))) | 38 | (cl-letf (((symbol-function 'default-file-modes) (lambda () #o775))) |
| 39 | (eshell-command-result-equal "umask" "002\n")) | 39 | (eshell-command-result-equal "umask" "002\n")) |
| @@ -43,7 +43,7 @@ | |||
| 43 | (cl-letf (((symbol-function 'default-file-modes) (lambda () #o1775))) | 43 | (cl-letf (((symbol-function 'default-file-modes) (lambda () #o1775))) |
| 44 | (eshell-command-result-equal "umask" "002\n"))) | 44 | (eshell-command-result-equal "umask" "002\n"))) |
| 45 | 45 | ||
| 46 | (ert-deftest em-basic-test/umask-read-symbolic () | 46 | (ert-deftest em-basic-test/umask/print-symbolic () |
| 47 | "Test printing umask symbolically." | 47 | "Test printing umask symbolically." |
| 48 | (cl-letf (((symbol-function 'default-file-modes) (lambda () #o775))) | 48 | (cl-letf (((symbol-function 'default-file-modes) (lambda () #o775))) |
| 49 | (eshell-command-result-equal "umask -S" | 49 | (eshell-command-result-equal "umask -S" |
| @@ -56,8 +56,8 @@ | |||
| 56 | (eshell-command-result-equal "umask -S" | 56 | (eshell-command-result-equal "umask -S" |
| 57 | "u=rwx,g=rwx,o=rx\n"))) | 57 | "u=rwx,g=rwx,o=rx\n"))) |
| 58 | 58 | ||
| 59 | (ert-deftest em-basic-test/umask-set () | 59 | (ert-deftest em-basic-test/umask/set-numeric () |
| 60 | "Test setting umask." | 60 | "Test setting umask numerically." |
| 61 | (let ((file-modes 0)) | 61 | (let ((file-modes 0)) |
| 62 | (cl-letf (((symbol-function 'set-default-file-modes) | 62 | (cl-letf (((symbol-function 'set-default-file-modes) |
| 63 | (lambda (mode) (setq file-modes mode)))) | 63 | (lambda (mode) (setq file-modes mode)))) |
| @@ -68,4 +68,30 @@ | |||
| 68 | (eshell-test-command-result "umask $(identity #o222)") | 68 | (eshell-test-command-result "umask $(identity #o222)") |
| 69 | (should (= file-modes #o555))))) | 69 | (should (= file-modes #o555))))) |
| 70 | 70 | ||
| 71 | (ert-deftest em-basic-test/umask/set-symbolic () | ||
| 72 | "Test setting umask symbolically." | ||
| 73 | (let ((file-modes 0)) | ||
| 74 | (cl-letf (((symbol-function 'default-file-modes) | ||
| 75 | (lambda() file-modes)) | ||
| 76 | ((symbol-function 'set-default-file-modes) | ||
| 77 | (lambda (mode) (setq file-modes mode)))) | ||
| 78 | (eshell-test-command-result "umask u=rwx,g=rwx,o=rx") | ||
| 79 | (should (= file-modes #o775)) | ||
| 80 | (eshell-test-command-result "umask u=rw,g=rx,o=x") | ||
| 81 | (should (= file-modes #o651)) | ||
| 82 | (eshell-test-command-result "umask u+x,o-x") | ||
| 83 | (should (= file-modes #o750)) | ||
| 84 | (eshell-test-command-result "umask a+rx") | ||
| 85 | (should (= file-modes #o755))))) | ||
| 86 | |||
| 87 | (ert-deftest em-basic-test/umask/set-with-S () | ||
| 88 | "Test that passing \"-S\" and a umask still sets the umask." | ||
| 89 | (let ((file-modes 0)) | ||
| 90 | (cl-letf (((symbol-function 'set-default-file-modes) | ||
| 91 | (lambda (mode) (setq file-modes mode)))) | ||
| 92 | (eshell-test-command-result "umask -S 002") | ||
| 93 | (should (= file-modes #o775)) | ||
| 94 | (eshell-test-command-result "umask -S 123") | ||
| 95 | (should (= file-modes #o654))))) | ||
| 96 | |||
| 71 | ;; em-basic-tests.el ends here | 97 | ;; em-basic-tests.el ends here |