diff options
| author | Tino Calancha | 2020-05-08 22:14:03 +0200 |
|---|---|---|
| committer | Tino Calancha | 2020-05-14 18:43:15 +0200 |
| commit | 3a284e578625e617fdc6085ae11da2b4e41bb59b (patch) | |
| tree | ff6c8708cc3cd9d892d2433be5adbf9156584157 | |
| parent | 4af8b17149ee04655f038229c6103963f247ff87 (diff) | |
| download | emacs-3a284e578625e617fdc6085ae11da2b4e41bb59b.tar.gz emacs-3a284e578625e617fdc6085ae11da2b4e41bb59b.zip | |
Combine archive-int-to-mode and tar-grind-file-modebug27952_combine-tar-grind-file-mode_archive-int-to-mode
Add a new function, file-modes-number-to-symbolic.
Make archive-int-to-mode and obsolete alias of it; use it
to define tar-grind-file-mode (Bug#27952).
* lisp/files.el (file-modes-number-to-symbolic): New defun.
* lisp/arc-mode.el (archive-int-to-mode): Make it an obsolete alias.
* lisp/tar-mode.el (tar-grind-file-mode):
Use file-modes-number-to-symbolic.
* test/lisp/arc-mode-tests.el (arc-mode-test-archive-int-to-mode)
* test/lisp/tar-mode-tests.el (tar-mode-test-tar-grind-file-mode):
Update test.
* test/lisp/files-tests.el (files-tests-file-modes-symbolic-to-number)
(files-tests-file-modes-number-to-symbolic): New tests.
* doc/lispref/files.texi (Changing Files): Document the new funtion.
* etc/NEWS (Lisp Changes in Emacs 28.1): Announce it.
| -rw-r--r-- | doc/lispref/files.texi | 5 | ||||
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/arc-mode.el | 24 | ||||
| -rw-r--r-- | lisp/files.el | 21 | ||||
| -rw-r--r-- | lisp/tar-mode.el | 20 | ||||
| -rw-r--r-- | test/lisp/arc-mode-tests.el | 2 | ||||
| -rw-r--r-- | test/lisp/files-tests.el | 36 | ||||
| -rw-r--r-- | test/lisp/tar-mode-tests.el | 3 |
8 files changed, 74 insertions, 41 deletions
diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi index b3ad9b99649..686dbdb1caf 100644 --- a/doc/lispref/files.texi +++ b/doc/lispref/files.texi | |||
| @@ -1909,6 +1909,11 @@ omitted or @code{nil}, it defaults to 0, i.e., no access rights at | |||
| 1909 | all. | 1909 | all. |
| 1910 | @end defun | 1910 | @end defun |
| 1911 | 1911 | ||
| 1912 | @defun file-modes-number-to-symbolic modes | ||
| 1913 | This function converts a numeric file mode specification in | ||
| 1914 | @var{modes} into the equivalent symbolic form. | ||
| 1915 | @end defun | ||
| 1916 | |||
| 1912 | @defun set-file-times filename &optional time flag | 1917 | @defun set-file-times filename &optional time flag |
| 1913 | This function sets the access and modification times of @var{filename} | 1918 | This function sets the access and modification times of @var{filename} |
| 1914 | to @var{time}. The return value is @code{t} if the times are successfully | 1919 | to @var{time}. The return value is @code{t} if the times are successfully |
| @@ -400,6 +400,10 @@ Use macro 'with-current-buffer-window' with action alist entry 'body-function'. | |||
| 400 | 400 | ||
| 401 | * Lisp Changes in Emacs 28.1 | 401 | * Lisp Changes in Emacs 28.1 |
| 402 | 402 | ||
| 403 | +++ | ||
| 404 | ** New function 'file-modes-number-to-symbolic' to convert a numeric | ||
| 405 | file mode specification into symbolic form. | ||
| 406 | |||
| 403 | ** New macro 'dlet' to dynamically bind variables. | 407 | ** New macro 'dlet' to dynamically bind variables. |
| 404 | 408 | ||
| 405 | ** The variable 'force-new-style-backquotes' has been removed. | 409 | ** The variable 'force-new-style-backquotes' has been removed. |
diff --git a/lisp/arc-mode.el b/lisp/arc-mode.el index c918f06c80e..6ce64fe24b3 100644 --- a/lisp/arc-mode.el +++ b/lisp/arc-mode.el | |||
| @@ -563,28 +563,8 @@ in which case a second argument, length LEN, should be supplied." | |||
| 563 | (aref str (- len i))))) | 563 | (aref str (- len i))))) |
| 564 | result)) | 564 | result)) |
| 565 | 565 | ||
| 566 | (defun archive-int-to-mode (mode) | 566 | (define-obsolete-function-alias 'archive-int-to-mode |
| 567 | "Turn an integer like 0700 (i.e., 448) into a mode string like -rwx------." | 567 | 'file-modes-number-to-symbolic "28.1") |
| 568 | ;; FIXME: merge with tar-grind-file-mode. | ||
| 569 | (if (null mode) | ||
| 570 | "??????????" | ||
| 571 | (string | ||
| 572 | (if (zerop (logand 8192 mode)) | ||
| 573 | (if (zerop (logand 16384 mode)) ?- ?d) | ||
| 574 | ?c) ; completeness | ||
| 575 | (if (zerop (logand 256 mode)) ?- ?r) | ||
| 576 | (if (zerop (logand 128 mode)) ?- ?w) | ||
| 577 | (if (zerop (logand 64 mode)) | ||
| 578 | (if (zerop (logand 2048 mode)) ?- ?S) | ||
| 579 | (if (zerop (logand 2048 mode)) ?x ?s)) | ||
| 580 | (if (zerop (logand 32 mode)) ?- ?r) | ||
| 581 | (if (zerop (logand 16 mode)) ?- ?w) | ||
| 582 | (if (zerop (logand 8 mode)) | ||
| 583 | (if (zerop (logand 1024 mode)) ?- ?S) | ||
| 584 | (if (zerop (logand 1024 mode)) ?x ?s)) | ||
| 585 | (if (zerop (logand 4 mode)) ?- ?r) | ||
| 586 | (if (zerop (logand 2 mode)) ?- ?w) | ||
| 587 | (if (zerop (logand 1 mode)) ?- ?x)))) | ||
| 588 | 568 | ||
| 589 | (defun archive-calc-mode (oldmode newmode) | 569 | (defun archive-calc-mode (oldmode newmode) |
| 590 | "From the integer OLDMODE and the string NEWMODE calculate a new file mode. | 570 | "From the integer OLDMODE and the string NEWMODE calculate a new file mode. |
diff --git a/lisp/files.el b/lisp/files.el index c34fe003880..dba704f7a4b 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -7552,6 +7552,27 @@ as in \"og+rX-w\"." | |||
| 7552 | op char-right))) | 7552 | op char-right))) |
| 7553 | num-rights)) | 7553 | num-rights)) |
| 7554 | 7554 | ||
| 7555 | (defun file-modes-number-to-symbolic (mode) | ||
| 7556 | (string | ||
| 7557 | (if (zerop (logand 8192 mode)) | ||
| 7558 | (if (zerop (logand 16384 mode)) ?- ?d) | ||
| 7559 | ?c) ; completeness | ||
| 7560 | (if (zerop (logand 256 mode)) ?- ?r) | ||
| 7561 | (if (zerop (logand 128 mode)) ?- ?w) | ||
| 7562 | (if (zerop (logand 64 mode)) | ||
| 7563 | (if (zerop (logand 2048 mode)) ?- ?S) | ||
| 7564 | (if (zerop (logand 2048 mode)) ?x ?s)) | ||
| 7565 | (if (zerop (logand 32 mode)) ?- ?r) | ||
| 7566 | (if (zerop (logand 16 mode)) ?- ?w) | ||
| 7567 | (if (zerop (logand 8 mode)) | ||
| 7568 | (if (zerop (logand 1024 mode)) ?- ?S) | ||
| 7569 | (if (zerop (logand 1024 mode)) ?x ?s)) | ||
| 7570 | (if (zerop (logand 4 mode)) ?- ?r) | ||
| 7571 | (if (zerop (logand 2 mode)) ?- ?w) | ||
| 7572 | (if (zerop (logand 512 mode)) | ||
| 7573 | (if (zerop (logand 1 mode)) ?- ?x) | ||
| 7574 | (if (zerop (logand 1 mode)) ?T ?t)))) | ||
| 7575 | |||
| 7555 | (defun file-modes-symbolic-to-number (modes &optional from) | 7576 | (defun file-modes-symbolic-to-number (modes &optional from) |
| 7556 | "Convert symbolic file modes to numeric file modes. | 7577 | "Convert symbolic file modes to numeric file modes. |
| 7557 | MODES is the string to convert, it should match | 7578 | MODES is the string to convert, it should match |
diff --git a/lisp/tar-mode.el b/lisp/tar-mode.el index a3c1715b1e1..73978ffc4a7 100644 --- a/lisp/tar-mode.el +++ b/lisp/tar-mode.el | |||
| @@ -480,23 +480,9 @@ checksum before doing the check." | |||
| 480 | 480 | ||
| 481 | (defun tar-grind-file-mode (mode) | 481 | (defun tar-grind-file-mode (mode) |
| 482 | "Construct a `rw-r--r--' string indicating MODE. | 482 | "Construct a `rw-r--r--' string indicating MODE. |
| 483 | MODE should be an integer which is a file mode value." | 483 | MODE should be an integer which is a file mode value. |
| 484 | (string | 484 | For instance, if mode is #o700, then it produces `rwx------'." |
| 485 | (if (zerop (logand 256 mode)) ?- ?r) | 485 | (substring (file-modes-number-to-symbolic mode) 1)) |
| 486 | (if (zerop (logand 128 mode)) ?- ?w) | ||
| 487 | (if (zerop (logand 2048 mode)) | ||
| 488 | (if (zerop (logand 64 mode)) ?- ?x) | ||
| 489 | (if (zerop (logand 64 mode)) ?S ?s)) | ||
| 490 | (if (zerop (logand 32 mode)) ?- ?r) | ||
| 491 | (if (zerop (logand 16 mode)) ?- ?w) | ||
| 492 | (if (zerop (logand 1024 mode)) | ||
| 493 | (if (zerop (logand 8 mode)) ?- ?x) | ||
| 494 | (if (zerop (logand 8 mode)) ?S ?s)) | ||
| 495 | (if (zerop (logand 4 mode)) ?- ?r) | ||
| 496 | (if (zerop (logand 2 mode)) ?- ?w) | ||
| 497 | (if (zerop (logand 512 mode)) | ||
| 498 | (if (zerop (logand 1 mode)) ?- ?x) | ||
| 499 | (if (zerop (logand 1 mode)) ?T ?t)))) | ||
| 500 | 486 | ||
| 501 | (defun tar-header-block-summarize (tar-hblock &optional mod-p) | 487 | (defun tar-header-block-summarize (tar-hblock &optional mod-p) |
| 502 | "Return a line similar to the output of `tar -vtf'." | 488 | "Return a line similar to the output of `tar -vtf'." |
diff --git a/test/lisp/arc-mode-tests.el b/test/lisp/arc-mode-tests.el index df658b98139..22ca7e2ec55 100644 --- a/test/lisp/arc-mode-tests.el +++ b/test/lisp/arc-mode-tests.el | |||
| @@ -28,7 +28,7 @@ | |||
| 28 | (let ((alist (list (cons 448 "-rwx------") | 28 | (let ((alist (list (cons 448 "-rwx------") |
| 29 | (cons 420 "-rw-r--r--") | 29 | (cons 420 "-rw-r--r--") |
| 30 | (cons 292 "-r--r--r--") | 30 | (cons 292 "-r--r--r--") |
| 31 | (cons 512 "----------") | 31 | (cons 512 "---------T") |
| 32 | (cons 1024 "------S---") ; Bug#28092 | 32 | (cons 1024 "------S---") ; Bug#28092 |
| 33 | (cons 2048 "---S------")))) | 33 | (cons 2048 "---S------")))) |
| 34 | (dolist (x alist) | 34 | (dolist (x alist) |
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index 05d9ceebf1d..4b902fd82ae 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el | |||
| @@ -1164,6 +1164,42 @@ works as expected if the default directory is quoted." | |||
| 1164 | (should-not (make-directory a/b t)) | 1164 | (should-not (make-directory a/b t)) |
| 1165 | (delete-directory dir 'recursive))) | 1165 | (delete-directory dir 'recursive))) |
| 1166 | 1166 | ||
| 1167 | (ert-deftest files-tests-file-modes-symbolic-to-number () | ||
| 1168 | (let ((alist (list (cons "a=rwx" #o777) | ||
| 1169 | (cons "o=t" #o1000) | ||
| 1170 | (cons "o=xt" #o1001) | ||
| 1171 | (cons "o=tx" #o1001) ; Order doesn't matter. | ||
| 1172 | (cons "u=rwx,g=rx,o=rx" #o755) | ||
| 1173 | (cons "u=rwx,g=,o=" #o700) | ||
| 1174 | (cons "u=rwx" #o700) ; Empty permissions can be ignored. | ||
| 1175 | (cons "u=rw,g=r,o=r" #o644) | ||
| 1176 | (cons "u=rw,g=r,o=t" #o1640) | ||
| 1177 | (cons "u=rw,g=r,o=xt" #o1641) | ||
| 1178 | (cons "u=rwxs,g=rs,o=xt" #o7741) | ||
| 1179 | (cons "u=rws,g=rs,o=t" #o7640) | ||
| 1180 | (cons "u=rws,g=rs,o=r" #o6644) | ||
| 1181 | (cons "a=r" #o444) | ||
| 1182 | (cons "u=S" nil) | ||
| 1183 | (cons "u=T" nil) | ||
| 1184 | (cons "u=Z" nil)))) | ||
| 1185 | (dolist (x alist) | ||
| 1186 | (if (cdr-safe x) | ||
| 1187 | (should (equal (cdr x) (file-modes-symbolic-to-number (car x)))) | ||
| 1188 | (should-error (file-modes-symbolic-to-number (car x))))))) | ||
| 1189 | |||
| 1190 | (ert-deftest files-tests-file-modes-number-to-symbolic () | ||
| 1191 | (let ((alist (list (cons #o755 "-rwxr-xr-x") | ||
| 1192 | (cons #o700 "-rwx------") | ||
| 1193 | (cons #o644 "-rw-r--r--") | ||
| 1194 | (cons #o1640 "-rw-r----T") | ||
| 1195 | (cons #o1641 "-rw-r----t") | ||
| 1196 | (cons #o7741 "-rwsr-S--t") | ||
| 1197 | (cons #o7640 "-rwSr-S--T") | ||
| 1198 | (cons #o6644 "-rwSr-Sr--") | ||
| 1199 | (cons #o444 "-r--r--r--")))) | ||
| 1200 | (dolist (x alist) | ||
| 1201 | (should (equal (cdr x) (file-modes-number-to-symbolic (car x))))))) | ||
| 1202 | |||
| 1167 | (ert-deftest files-tests-no-file-write-contents () | 1203 | (ert-deftest files-tests-no-file-write-contents () |
| 1168 | "Test that `write-contents-functions' permits saving a file. | 1204 | "Test that `write-contents-functions' permits saving a file. |
| 1169 | Usually `basic-save-buffer' will prompt for a file name if the | 1205 | Usually `basic-save-buffer' will prompt for a file name if the |
diff --git a/test/lisp/tar-mode-tests.el b/test/lisp/tar-mode-tests.el index bc41b863da7..f05389df60f 100644 --- a/test/lisp/tar-mode-tests.el +++ b/test/lisp/tar-mode-tests.el | |||
| @@ -29,7 +29,8 @@ | |||
| 29 | (cons 420 "rw-r--r--") | 29 | (cons 420 "rw-r--r--") |
| 30 | (cons 292 "r--r--r--") | 30 | (cons 292 "r--r--r--") |
| 31 | (cons 512 "--------T") | 31 | (cons 512 "--------T") |
| 32 | (cons 1024 "-----S---")))) | 32 | (cons 1024 "-----S---") |
| 33 | (cons 2048 "--S------")))) | ||
| 33 | (dolist (x alist) | 34 | (dolist (x alist) |
| 34 | (should (equal (cdr x) (tar-grind-file-mode (car x))))))) | 35 | (should (equal (cdr x) (tar-grind-file-mode (car x))))))) |
| 35 | 36 | ||