[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/compat a92aec7251 19/27: Add file-modes-number-to-symbo
From: |
ELPA Syncer |
Subject: |
[elpa] externals/compat a92aec7251 19/27: Add file-modes-number-to-symbolic |
Date: |
Sat, 5 Mar 2022 04:57:28 -0500 (EST) |
branch: externals/compat
commit a92aec72518100df0d8f453c15d42d00ecdd28ed
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>
Add file-modes-number-to-symbolic
---
MANUAL | 2 ++
compat-28.el | 38 ++++++++++++++++++++++++++++++++++++++
compat-tests.el | 14 ++++++++++++++
3 files changed, 54 insertions(+)
diff --git a/MANUAL b/MANUAL
index 56d6967cdd..37978a46d6 100644
--- a/MANUAL
+++ b/MANUAL
@@ -353,6 +353,8 @@ provided by compat by default:
- Function ~button-buttonize~ :: Defined in ~button.el~.
- Function ~make-directory-autoloads~ :: See [[info:elisp#Autoload][(elisp)
Autoload]].
- Function ~color-values-from-color-spec~ :: Defined in ~xfaces.c~.
+- Function ~file-modes-number-to-symbolic~ :: See [[info:elisp#Changing
Files][(elisp) Changing
+ Files]].
These functions are prefixed with ~compat~ prefix, and are only loaded
when ~compat-28~ is required:
diff --git a/compat-28.el b/compat-28.el
index 37d12f9e1c..6324126e8c 100644
--- a/compat-28.el
+++ b/compat-28.el
@@ -625,6 +625,44 @@ See `file-symlink-p' to distinguish symlinks."
(and (file-directory-p dir)
(null (directory-files dir nil directory-files-no-dot-files-regexp t))))
+(compat-defun file-modes-number-to-symbolic (mode &optional filetype)
+ "Return a string describing a file's MODE.
+For instance, if MODE is #o700, then it produces `-rwx------'.
+FILETYPE if provided should be a character denoting the type of file,
+such as `?d' for a directory, or `?l' for a symbolic link and will override
+the leading `-' char."
+ (string
+ (or filetype
+ (pcase (lsh mode -12)
+ ;; POSIX specifies that the file type is included in st_mode
+ ;; and provides names for the file types but values only for
+ ;; the permissions (e.g., S_IWOTH=2).
+
+ ;; (#o017 ??) ;; #define S_IFMT 00170000
+ (#o014 ?s) ;; #define S_IFSOCK 0140000
+ (#o012 ?l) ;; #define S_IFLNK 0120000
+ ;; (8 ??) ;; #define S_IFREG 0100000
+ (#o006 ?b) ;; #define S_IFBLK 0060000
+ (#o004 ?d) ;; #define S_IFDIR 0040000
+ (#o002 ?c) ;; #define S_IFCHR 0020000
+ (#o001 ?p) ;; #define S_IFIFO 0010000
+ (_ ?-)))
+ (if (zerop (logand 256 mode)) ?- ?r)
+ (if (zerop (logand 128 mode)) ?- ?w)
+ (if (zerop (logand 64 mode))
+ (if (zerop (logand 2048 mode)) ?- ?S)
+ (if (zerop (logand 2048 mode)) ?x ?s))
+ (if (zerop (logand 32 mode)) ?- ?r)
+ (if (zerop (logand 16 mode)) ?- ?w)
+ (if (zerop (logand 8 mode))
+ (if (zerop (logand 1024 mode)) ?- ?S)
+ (if (zerop (logand 1024 mode)) ?x ?s))
+ (if (zerop (logand 4 mode)) ?- ?r)
+ (if (zerop (logand 2 mode)) ?- ?w)
+ (if (zerop (logand 512 mode))
+ (if (zerop (logand 1 mode)) ?- ?x)
+ (if (zerop (logand 1 mode)) ?T ?t))))
+
;;;; Defined in minibuffer.el
(compat-defun format-prompt (prompt default &rest format-args)
diff --git a/compat-tests.el b/compat-tests.el
index 2ad7951ed6..6d781d25ca 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -1685,5 +1685,19 @@ the compatibility function."
;; (compat--should nil "rgbi: 0/ 0/ 0")
(compat--should nil "rgbi : 0/0/0")))
+(ert-deftest compat-file-modes-number-to-symbolic ()
+ "Check if `compat--file-modes-number-to-symbolic' was implemented properly."
+ (compat-test file-modes-number-to-symbolic
+ (compat--should "-rwx------" #o700)
+ (compat--should "-rwxrwx---" #o770)
+ (compat--should "-rwx---rwx" #o707)
+ (compat--should "-rw-r-xr--" #o654)
+ (compat--should "--wx-w---x" #o321)
+ (compat--should "drwx------" #o700 ?d)
+ (compat--should "?rwx------" #o700 ??)
+ (compat--should "lrwx------" #o120700)
+ (compat--should "prwx------" #o10700)
+ (compat--should "-rwx------" #o30700)))
+
(provide 'compat-tests)
;;; compat-tests.el ends here
- [elpa] externals/compat 4aca90834f 09/27: Add get-pos-property to missing functions in 24.4, (continued)
- [elpa] externals/compat 4aca90834f 09/27: Add get-pos-property to missing functions in 24.4, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 3f511afce0 12/27: Add directory-files-recursively, ELPA Syncer, 2022/03/05
- [elpa] externals/compat efa6e171e5 13/27: Document define-advice as not implemented, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 441539ae8b 11/27: Add face-spec-set, ELPA Syncer, 2022/03/05
- [elpa] externals/compat b3b75333b1 14/27: Document generators as not implemented, ELPA Syncer, 2022/03/05
- [elpa] externals/compat c4893fa014 15/27: Document bufferpos-to-filepos as not implemented, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 35072b3d25 22/27: Fix if-let and add tests, ELPA Syncer, 2022/03/05
- [elpa] externals/compat ece91a5b89 03/27: Add function-put, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 9034bcc0ac 05/27: Fix broken markup in some deftest docstrings, ELPA Syncer, 2022/03/05
- [elpa] externals/compat c8bc47b671 18/27: Add replace-string-in-region, ELPA Syncer, 2022/03/05
- [elpa] externals/compat a92aec7251 19/27: Add file-modes-number-to-symbolic,
ELPA Syncer <=
- [elpa] externals/compat ba2918d6d3 21/27: Add file-backup-file-names, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 15ca463a9e 20/27: Document that null-device and path-separator are not implemented, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 6b14d5fa3b 24/27: Exclude the generated manual from the repository, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 63ac5dd347 16/27: Add assoc-delete-all, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 8eb72a2739 25/27: Convert JSON advice for Emacs 28 to prefixed functions, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 9fa3fbab8a 27/27: Fix (provide) in compat-tests.el, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 5514de45e1 26/27: Rewrite test macros to generate more individual tests, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 212f8c7c77 17/27: Add color-values-from-color-spec, ELPA Syncer, 2022/03/05
- [elpa] externals/compat 158edd3161 23/27: Mark all currently untested functions, ELPA Syncer, 2022/03/05