From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#27952: 26.0.50; Combine archive-int-to-mode and tar-grind-file-mode Date: Fri, 8 May 2020 22:20:15 +0200 (CEST) Message-ID: References: <8760e3zf6v.fsf@calancha-pc> <87h83bqfem.fsf@marxist.se> <871rnzzzgd.fsf@stefankangas.se> Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="1321"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Alpine 2.21 (DEB 202 2017-01-01) Cc: Stefan Kangas , Lars Ingebrigtsen , 27952@debbugs.gnu.org, Tino Calancha To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri May 08 22:21:11 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jX9Ud-0000E6-Kv for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 08 May 2020 22:21:11 +0200 Original-Received: from localhost ([::1]:38212 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jX9Uc-00048Z-AE for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 08 May 2020 16:21:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43628) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jX9UU-00048Q-Lp for bug-gnu-emacs@gnu.org; Fri, 08 May 2020 16:21:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34855) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jX9UU-0008Ly-Bx for bug-gnu-emacs@gnu.org; Fri, 08 May 2020 16:21:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jX9UU-00067U-7y for bug-gnu-emacs@gnu.org; Fri, 08 May 2020 16:21:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 08 May 2020 20:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 27952 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 27952-submit@debbugs.gnu.org id=B27952.158896922623447 (code B ref 27952); Fri, 08 May 2020 20:21:02 +0000 Original-Received: (at 27952) by debbugs.gnu.org; 8 May 2020 20:20:26 +0000 Original-Received: from localhost ([127.0.0.1]:46401 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jX9Tu-000666-1a for submit@debbugs.gnu.org; Fri, 08 May 2020 16:20:26 -0400 Original-Received: from mail-wm1-f42.google.com ([209.85.128.42]:40006) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jX9Tr-00065q-VI for 27952@debbugs.gnu.org; Fri, 08 May 2020 16:20:24 -0400 Original-Received: by mail-wm1-f42.google.com with SMTP id u16so11991943wmc.5 for <27952@debbugs.gnu.org>; Fri, 08 May 2020 13:20:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=s7aVXq2YDJyxLOBsnXbz7E33cV5buWcV5RQG4Ylz7mY=; b=P/+a4dsQQ4o6wn2NdgPIruOTVCS7NGzl+xyxVAsJy3st/0h8E5udCkxFjGYAUjqpbO oOo06q5aJewiYnGTqEnn99+purdU3Jt8SHHvGNMtVhtue0hQL5FzsuAXZ0aaiELuUNDw aIEavljyoQ+e70zfKR0t8kRh76DdBJstMz9+IctskhEyWtwJD/Ug05Ot9NAxmyOxzSh+ vhba/93AIQnUkx3aUp6SKNgVSImZShnCagWIyRT22PKzAYYCu+kpCVt3laQkw72ZC7kR G1mFWgVj5GI2tQPuTxK78iBptK2g0PoZdjEvD13n3KNtW6kSD4Dr14R5xcDxzKP/hm1E enig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=s7aVXq2YDJyxLOBsnXbz7E33cV5buWcV5RQG4Ylz7mY=; b=oArIsiWWxiLU/fDU+ADMsM7CLVHxG+bMo7Z1SRW3teBi/OcVyG7HujIaoWbwtx3KKt mz6lU5l295MJrT+6zOaJn5lFrRp8RTa0bm/3SjA3cIyh/aikO5u4AxqWy2Tw26CF4mYk f2ZRsxHxJ0AKzfSmV2YqdD+LcCk9+fPkVX4XZlEw/xGSNsVvas3g554/XIeTF6WapcmW 3xhtGTr097rSsQim5A/t3qoTweYgyKd0ffaJ/dfBovDcOpXqp0KX2mYg+JhaIoAw4IBO NjGBDs/Wqcz5LqLF59M2ATEEmY5GKVUP1nzt/Db+JpflRAxCbbLHLPSOinMbZAqZUA86 fgJw== X-Gm-Message-State: AGi0PuamdzAxSviVtyChhR1FyReGVUDNa7jlEwoOGrPmW1W+ckrCko42 n8Hib6bFpTB6BTPm75Hqxa0= X-Google-Smtp-Source: APiQypJc4D/7MkEryNP50XGKspjoYTrfpBRWzmS4QSEH6WMhEaC09yip40j6nl9eoTaETxOol/UH8g== X-Received: by 2002:a05:600c:230f:: with SMTP id 15mr14922513wmo.101.1588969217863; Fri, 08 May 2020 13:20:17 -0700 (PDT) Original-Received: from calancha-pc.dy.bbexcite.jp ([31.7.242.222]) by smtp.gmail.com with ESMTPSA id q2sm3034443wrx.60.2020.05.08.13.20.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 May 2020 13:20:17 -0700 (PDT) X-Google-Original-From: Tino Calancha X-X-Sender: calancha@calancha-pc.dy.bbexcite.jp In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:179942 Archived-At: On Fri, 8 May 2020, Stefan Monnier wrote: >> +(defalias 'archive-int-to-mode 'file-modes-number-to-symbolic) > > Make it a `define-obsolete-function-alias`. OK. >> (defun tar-grind-file-mode (mode) >> "Construct a `rw-r--r--' string indicating MODE. > [...] >> +MODE should be an integer which is a file mode value. >> +For instance, if mode is #o700, then it produces `rwx------'." >> + (substring (file-modes-number-to-symbolic mode) 1)) > > LGTM. Good. Then, I will merge it next week. > A second step might be to mark this function as obsolete and > update all the call sites so they are happy with the output format of > `file-modes-number-to-symbolic`. It sounds good; it's funny having those 2 defun with almost identical output. Maybe you can add a TODO in the code asking for this; people feel encouraged to contribute when they found those FIXME/TODOs. Amended patch follows: --8<-----------------------------cut here---------------start------------->8--- commit 043ecae1c0828bcad94083ef456195ae21675a1a Author: Tino Calancha Date: Fri May 8 22:14:03 2020 +0200 Combine archive-int-to-mode and tar-grind-file-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. diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi index b3ad9b9964..686dbdb1ca 100644 --- a/doc/lispref/files.texi +++ b/doc/lispref/files.texi @@ -1909,6 +1909,11 @@ Changing Files all. @end defun +@defun file-modes-number-to-symbolic modes +This function converts a numeric file mode specification in +@var{modes} into the equivalent symbolic form. +@end defun + @defun set-file-times filename &optional time flag This function sets the access and modification times of @var{filename} to @var{time}. The return value is @code{t} if the times are successfully diff --git a/etc/NEWS b/etc/NEWS index ac93a76ff9..26426fc42b 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -372,6 +372,10 @@ Use macro 'with-current-buffer-window' with action alist entry 'body-function'. * Lisp Changes in Emacs 28.1 ++++ +** New function 'file-modes-number-to-symbolic' to convert a numeric +file mode specification into symbolic form. + ** New macro 'dlet' to dynamically bind variables. ** The variable 'force-new-style-backquotes' has been removed. diff --git a/lisp/arc-mode.el b/lisp/arc-mode.el index c918f06c80..6ce64fe24b 100644 --- a/lisp/arc-mode.el +++ b/lisp/arc-mode.el @@ -563,28 +563,8 @@ archive-l-e (aref str (- len i))))) result)) -(defun archive-int-to-mode (mode) - "Turn an integer like 0700 (i.e., 448) into a mode string like -rwx------." - ;; FIXME: merge with tar-grind-file-mode. - (if (null mode) - "??????????" - (string - (if (zerop (logand 8192 mode)) - (if (zerop (logand 16384 mode)) ?- ?d) - ?c) ; completeness - (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 1 mode)) ?- ?x)))) +(define-obsolete-function-alias 'archive-int-to-mode + 'file-modes-number-to-symbolic "28.1") (defun archive-calc-mode (oldmode newmode) "From the integer OLDMODE and the string NEWMODE calculate a new file mode. diff --git a/lisp/files.el b/lisp/files.el index c34fe00388..dba704f7a4 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -7552,6 +7552,27 @@ file-modes-rights-to-number op char-right))) num-rights)) +(defun file-modes-number-to-symbolic (mode) + (string + (if (zerop (logand 8192 mode)) + (if (zerop (logand 16384 mode)) ?- ?d) + ?c) ; completeness + (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)))) + (defun file-modes-symbolic-to-number (modes &optional from) "Convert symbolic file modes to numeric file modes. MODES is the string to convert, it should match diff --git a/lisp/tar-mode.el b/lisp/tar-mode.el index a3c1715b1e..73978ffc4a 100644 --- a/lisp/tar-mode.el +++ b/lisp/tar-mode.el @@ -480,23 +480,9 @@ tar-clip-time-string (defun tar-grind-file-mode (mode) "Construct a `rw-r--r--' string indicating MODE. -MODE should be an integer which is a file mode value." - (string - (if (zerop (logand 256 mode)) ?- ?r) - (if (zerop (logand 128 mode)) ?- ?w) - (if (zerop (logand 2048 mode)) - (if (zerop (logand 64 mode)) ?- ?x) - (if (zerop (logand 64 mode)) ?S ?s)) - (if (zerop (logand 32 mode)) ?- ?r) - (if (zerop (logand 16 mode)) ?- ?w) - (if (zerop (logand 1024 mode)) - (if (zerop (logand 8 mode)) ?- ?x) - (if (zerop (logand 8 mode)) ?S ?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)))) +MODE should be an integer which is a file mode value. +For instance, if mode is #o700, then it produces `rwx------'." + (substring (file-modes-number-to-symbolic mode) 1)) (defun tar-header-block-summarize (tar-hblock &optional mod-p) "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 df658b9813..22ca7e2ec5 100644 --- a/test/lisp/arc-mode-tests.el +++ b/test/lisp/arc-mode-tests.el @@ -28,7 +28,7 @@ arc-mode-tests-data-directory (let ((alist (list (cons 448 "-rwx------") (cons 420 "-rw-r--r--") (cons 292 "-r--r--r--") - (cons 512 "----------") + (cons 512 "---------T") (cons 1024 "------S---") ; Bug#28092 (cons 2048 "---S------")))) (dolist (x alist) diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index 05d9ceebf1..4b902fd82a 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -1164,6 +1164,42 @@ files-tests-file-attributes-equal (should-not (make-directory a/b t)) (delete-directory dir 'recursive))) +(ert-deftest files-tests-file-modes-symbolic-to-number () + (let ((alist (list (cons "a=rwx" #o777) + (cons "o=t" #o1000) + (cons "o=xt" #o1001) + (cons "o=tx" #o1001) ; Order doesn't matter. + (cons "u=rwx,g=rx,o=rx" #o755) + (cons "u=rwx,g=,o=" #o700) + (cons "u=rwx" #o700) ; Empty permissions can be ignored. + (cons "u=rw,g=r,o=r" #o644) + (cons "u=rw,g=r,o=t" #o1640) + (cons "u=rw,g=r,o=xt" #o1641) + (cons "u=rwxs,g=rs,o=xt" #o7741) + (cons "u=rws,g=rs,o=t" #o7640) + (cons "u=rws,g=rs,o=r" #o6644) + (cons "a=r" #o444) + (cons "u=S" nil) + (cons "u=T" nil) + (cons "u=Z" nil)))) + (dolist (x alist) + (if (cdr-safe x) + (should (equal (cdr x) (file-modes-symbolic-to-number (car x)))) + (should-error (file-modes-symbolic-to-number (car x))))))) + +(ert-deftest files-tests-file-modes-number-to-symbolic () + (let ((alist (list (cons #o755 "-rwxr-xr-x") + (cons #o700 "-rwx------") + (cons #o644 "-rw-r--r--") + (cons #o1640 "-rw-r----T") + (cons #o1641 "-rw-r----t") + (cons #o7741 "-rwsr-S--t") + (cons #o7640 "-rwSr-S--T") + (cons #o6644 "-rwSr-Sr--") + (cons #o444 "-r--r--r--")))) + (dolist (x alist) + (should (equal (cdr x) (file-modes-number-to-symbolic (car x))))))) + (ert-deftest files-tests-no-file-write-contents () "Test that `write-contents-functions' permits saving a file. 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 bc41b863da..f05389df60 100644 --- a/test/lisp/tar-mode-tests.el +++ b/test/lisp/tar-mode-tests.el @@ -29,7 +29,8 @@ tar-mode-tests-data-directory (cons 420 "rw-r--r--") (cons 292 "r--r--r--") (cons 512 "--------T") - (cons 1024 "-----S---")))) + (cons 1024 "-----S---") + (cons 2048 "--S------")))) (dolist (x alist) (should (equal (cdr x) (tar-grind-file-mode (car x))))))) --8<-----------------------------cut here---------------end--------------->8--- In GNU Emacs 28.0.50 (build 4, x86_64-pc-linux-gnu, GTK+ Version 3.24.5, cairo version 1.16.0) of 2020-05-08 built on calancha-pc.dy.bbexcite.jp Repository revision: 4b8e6939bf7664fda33a7aaa03d2d8069358ff7b Repository branch: master Windowing system distributor 'The X.Org Foundation', version 11.0.12004000 System Description: Debian GNU/Linux 10 (buster)