GNU bug report logs - #61708
28.2; file-modes-symbolic-to-number inconsistency

Previous Next

Package: emacs;

Reported by: Thierry Volpiatto <thievol <at> posteo.net>

Date: Wed, 22 Feb 2023 13:59:02 UTC

Severity: normal

Found in version 28.2

Full log


Message #32 received at 61708 <at> debbugs.gnu.org (full text, mbox):

From: Thierry Volpiatto <thievol <at> posteo.net>
To: Gregory Heytings <gregory <at> heytings.org>
Cc: Andreas Schwab <schwab <at> suse.de>, 61708 <at> debbugs.gnu.org
Subject: Re: bug#61708: 28.2; file-modes-symbolic-to-number inconsistency
Date: Thu, 23 Feb 2023 04:44:10 +0000
[Message part 1 (text/plain, inline)]
Gregory Heytings <gregory <at> 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
[signature.asc (application/pgp-signature, inline)]

This bug report was last modified 2 years and 116 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.