unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Thierry Volpiatto <thievol@posteo.net>
To: Gregory Heytings <gregory@heytings.org>
Cc: Andreas Schwab <schwab@suse.de>, 61708@debbugs.gnu.org
Subject: bug#61708: 28.2; file-modes-symbolic-to-number inconsistency
Date: Thu, 23 Feb 2023 04:44:10 +0000	[thread overview]
Message-ID: <87cz61ufrf.fsf@posteo.net> (raw)
In-Reply-To: <e737b605e9ca59a62fd5@heytings.org>

[-- Attachment #1: Type: text/plain, Size: 1165 bytes --]


Gregory Heytings <gregory@heytings.org> writes:

>>>> How one convert the output of (nth 8 (file-attributes
>>>> "/home/user")) to numeric mode?
>>>
>>> (file-modes "/home/user")
>>
>> Yes, thanks I know this one, what I want to convert is
>> e.g. "-rwxr-x---" to number.
>>
>
> (defun symbolic-mode-to-number (mode)
>   (string-to-number
>    (replace-regexp-in-string
>     "[^0]" "1"
>     (string-replace "-" "0" mode))
>    2))

Nice! I never used the BASE argument of string-to-number probably due to
my catastrophic math level :-), however this is very basic and doesn't
cover modes like "-rwxrwxrwt" or "-rwsr-xr-x".

I already wrote the needed functions for my needs (helm), however what I
had like is to clarify the usage of `file-modes-symbolic-to-number' in
docstring (examples?).
As Andrea pointed the MODES argument handle (+-=) like chmod would do
i.e. the function returns the numeric mode that for example chmod would set on
a file. Once you know it that's fine , you remove the "-" in MODES like
read-file-modes does otherwise you may think it interpret the mode that
a file already has.

Thanks.

-- 
Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 686 bytes --]

  reply	other threads:[~2023-02-23  4:44 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-22 13:49 bug#61708: 28.2; file-modes-symbolic-to-number inconsistency Thierry Volpiatto
2023-02-22 14:16 ` Thierry Volpiatto
2023-02-22 14:26 ` Andreas Schwab
2023-02-22 14:58   ` Thierry Volpiatto
2023-02-22 15:45     ` Andreas Schwab
2023-02-22 17:03       ` Thierry Volpiatto
2023-02-22 17:11         ` Gregory Heytings
2023-02-22 17:44           ` Thierry Volpiatto
2023-02-22 21:40             ` Gregory Heytings
2023-02-23  4:44               ` Thierry Volpiatto [this message]
2023-02-23  6:08               ` Eli Zaretskii
2023-02-23  7:00                 ` Thierry Volpiatto
2023-02-23  9:18               ` Andreas Schwab
2023-02-23  9:27                 ` Gregory Heytings
2023-02-23  9:14         ` Andreas Schwab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87cz61ufrf.fsf@posteo.net \
    --to=thievol@posteo.net \
    --cc=61708@debbugs.gnu.org \
    --cc=gregory@heytings.org \
    --cc=schwab@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).