From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!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, 04 Aug 2017 21:32:24 +0900 Message-ID: <8760e3zf6v.fsf@calancha-pc> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1501855068 18627 195.159.176.226 (4 Aug 2017 13:57:48 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 4 Aug 2017 13:57:48 +0000 (UTC) Cc: stefan monnier To: 27952@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Aug 04 15:57:44 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ddd6j-0004V5-6R for geb-bug-gnu-emacs@m.gmane.org; Fri, 04 Aug 2017 15:57:41 +0200 Original-Received: from localhost ([::1]:51500 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddd6m-0007tC-HN for geb-bug-gnu-emacs@m.gmane.org; Fri, 04 Aug 2017 09:57:44 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35745) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddd57-0006PF-Q2 for bug-gnu-emacs@gnu.org; Fri, 04 Aug 2017 09:57:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddd4A-00007M-EJ for bug-gnu-emacs@gnu.org; Fri, 04 Aug 2017 09:56:01 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:38494) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ddd4A-000072-50 for bug-gnu-emacs@gnu.org; Fri, 04 Aug 2017 09:55:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ddd49-0001EM-S2; Fri, 04 Aug 2017 09:55:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: monnier@iro.umontreal.ca, bug-gnu-emacs@gnu.org Resent-Date: Fri, 04 Aug 2017 13:55:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 27952 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: stefan monnier Original-Received: via spool by submit@debbugs.gnu.org id=B.15018548414630 (code B ref -1); Fri, 04 Aug 2017 13:55:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 4 Aug 2017 13:54:01 +0000 Original-Received: from localhost ([127.0.0.1]:41156 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ddd3B-0001CU-40 for submit@debbugs.gnu.org; Fri, 04 Aug 2017 09:54:01 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:41918) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ddd39-0001CJ-7i for submit@debbugs.gnu.org; Fri, 04 Aug 2017 09:54:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddd20-0006NT-6J for submit@debbugs.gnu.org; Fri, 04 Aug 2017 09:53:54 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:59291) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ddd1z-0006M5-Kd for submit@debbugs.gnu.org; Fri, 04 Aug 2017 09:52:47 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55588) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddd11-0000QN-0v for bug-gnu-emacs@gnu.org; Fri, 04 Aug 2017 09:52:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddbmJ-0007GF-CV for bug-gnu-emacs@gnu.org; Fri, 04 Aug 2017 08:33:40 -0400 Original-Received: from mail-pg0-x231.google.com ([2607:f8b0:400e:c05::231]:38619) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ddbmJ-0007F5-0L for bug-gnu-emacs@gnu.org; Fri, 04 Aug 2017 08:32:31 -0400 Original-Received: by mail-pg0-x231.google.com with SMTP id l64so7497711pge.5 for ; Fri, 04 Aug 2017 05:32:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=V2tSIRjz35gWamMP95JyYDFzviTCJ4od/vaKrX8/Xe4=; b=jpKtgRMOQZoCXhiqVdqHAw91MjtnYq0ubAkfPsFGtUGovDMmnz3GwLayhPjkyzLnSI XtXZ6DYdutLP8qQv3AjSz+eVwk58V+DL83hU+Gg2aoYZg5uMSUAWAA0du2G0YoT52MX5 ursgxqhinn2BQQWFiLgbk4H8OYp5fNvRbdvOnn7WZa/QJaamGaNBcGiH7Rvf291GFZNS YaFbqZA+HMQsk9Iuxmd0IvD1EIp8i/wy4lnKgIDKwVjZX6gC7smxrMKdIHKC3cd59BmK COx/6OYlN6UKEsQZglhLecXYsaXI+9kChfOxNDdWW19Lk6mVXPXSjN68GKyKywkbWQHy jnog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=V2tSIRjz35gWamMP95JyYDFzviTCJ4od/vaKrX8/Xe4=; b=EzETkbTdZyzIkt9q6tLyhzm+UMiN7THCVFWiFvGSd2BBd4HlTQlLzvppMPGPVEQ0jl GxBUrnpN6MwWvob+oAnnBJ3M66p8Wpq8WunO6qIuxwqDG09whjXsDHlERSge0Xb5YVRD Oag6sUzITG81IgdkDhmJdf1qD6K2yqtweuuf0IB7nowSuc3dyV8lwgkqdMITKS6pwn5n +KRL5ZJbCy88q+d/oIv4EjKfhdtoXPINnIMbxAjncYUaj9WvNlmiu2cUWpdZOWJmNxUx 9IkkK+jIxbeZHVuZOInyBw0fJdtzrNxqDV8W8xmkmTyuh4R8nkjj8xZnOHIqJwfKTtB0 zaxw== X-Gm-Message-State: AIVw1136nKbdMgW21TfCboyJzwtx2LmKCzMmmUeNvZUwb1R220hbZi+Y Lqxs4rG5Jqz49xDQ X-Received: by 10.84.241.76 with SMTP id u12mr2631863plm.196.1501849949696; Fri, 04 Aug 2017 05:32:29 -0700 (PDT) Original-Received: from calancha-pc (170.224.128.101.dy.bbexcite.jp. [101.128.224.170]) by smtp.gmail.com with ESMTPSA id f88sm3354579pff.74.2017.08.04.05.32.28 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2017 05:32:29 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:135338 Archived-At: Severity: wishlist Tag: patch X-Debbugs-CC: Stefan Monnier These functions are almost identical; archive-int-to-mode has a FIXME suggesting merging it with tar-grind-file-mode. --8<-----------------------------cut here---------------start------------->8--- commit c6d36b04de7f6442653af7e4699bdad44ee57201 Author: Tino Calancha Date: Fri Aug 4 21:25:44 2017 +0900 Combine archive-int-to-mode and tar-grind-file-mode These functions are almost identical. Add a new function file-modes-number-to-symbolic; use it to define the other two. * lisp/files.el (file-modes-number-to-symbolic-1) (file-modes-number-to-symbolic): New defuns. * lisp/arc-mode.el (archive-int-to-mode): Define as a alias of file-modes-number-to-symbolic. * lisp/tar-mode.el (tar-grind-file-mode): Fix docstring. Use file-modes-number-to-symbolic. diff --git a/lisp/arc-mode.el b/lisp/arc-mode.el index bd7548b704..8f3691b337 100644 --- a/lisp/arc-mode.el +++ b/lisp/arc-mode.el @@ -549,26 +549,7 @@ 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. - (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 1024 mode)) ?- ?S) - (if (zerop (logand 1024 mode)) ?x ?s)) - (if (zerop (logand 32 mode)) ?- ?r) - (if (zerop (logand 16 mode)) ?- ?w) - (if (zerop (logand 8 mode)) - (if (zerop (logand 2048 mode)) ?- ?S) - (if (zerop (logand 2048 mode)) ?x ?s)) - (if (zerop (logand 4 mode)) ?- ?r) - (if (zerop (logand 2 mode)) ?- ?w) - (if (zerop (logand 1 mode)) ?- ?x))) +(defalias 'archive-int-to-mode 'file-modes-number-to-symbolic) (defun archive-calc-mode (oldmode newmode &optional error) "From the integer OLDMODE and the string NEWMODE calculate a new file mode. diff --git a/lisp/files.el b/lisp/files.el index 89f6f9f44d..e776b00b91 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -7188,6 +7188,65 @@ file-modes-symbolic-to-number (error "Parse error in modes near `%s'" (substring modes 0)))) num-modes))) +(defun file-modes-number-to-symbolic-1 (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 1024 mode)) ?- ?S) + (if (zerop (logand 1024 mode)) ?x ?s)) + (if (zerop (logand 32 mode)) ?- ?r) + (if (zerop (logand 16 mode)) ?- ?w) + (if (zerop (logand 8 mode)) + (if (zerop (logand 2048 mode)) ?- ?S) + (if (zerop (logand 2048 mode)) ?x ?s)) + (if (zerop (logand 4 mode)) ?- ?r) + (if (zerop (logand 2 mode)) ?- ?w) + (if (zerop (logand 1 mode)) ?- ?x))) + +(defun file-modes-number-to-symbolic (mode &optional detailed from) + "Turn an integer like 0700 (i.e., 448) into a mode string like -rwx------. +If optional arg DETAILED is non-nil, then use the format 'u=rwx,g=,o='. +If optional argument FROM is non-nil, then it's the original file mode + to compare with MODE. FROM is ignored unless DETAILED is non-nil. + +For instance, if MODE is 448, DETAILED is non-nil, and FROM is 400, +the output is 'u+x,g-w'." + (let ((mode (file-modes-number-to-symbolic-1 mode)) + (from (and from (substring (file-modes-number-to-symbolic-1 from) 1)))) + (if (not detailed) + mode + (setq mode (substring mode 1)) + (cond (from + (let ((res "u")) + (dotimes (i (length mode)) + (let ((x (aref mode i)) + (y (aref from i))) + (when (= i 3) (setq res (concat res ",g"))) + (when (= i 6) (setq res (concat res ",o"))) + (setq res (concat res + (cond ((eq x y) "") + ((eq x ?-) (string ?- y)) + ((eq y ?-) (string ?+ x))))))) + (replace-regexp-in-string + ",\\'" "" + (replace-regexp-in-string + "u," "" + (replace-regexp-in-string + "g," "" + (replace-regexp-in-string + "o\\'" "" res)))))) + (t + (replace-regexp-in-string + "-" "" + (format "u=%s,g=%s,o=%s" + (substring mode 0 3) + (substring mode 3 6) + (substring mode 6)))))))) + (defun read-file-modes (&optional prompt orig-file) "Read file modes in octal or symbolic notation and return its numeric value. PROMPT is used as the prompt, default to \"File modes (octal or symbolic): \". diff --git a/lisp/tar-mode.el b/lisp/tar-mode.el index 1d453d2980..f41cc25532 100644 --- a/lisp/tar-mode.el +++ b/lisp/tar-mode.el @@ -469,24 +469,12 @@ tar-clip-time-string (concat " " (substring str 4 16) (format-time-string " %Y" time)))) (defun tar-grind-file-mode (mode) - "Construct a `-rw--r--r--' string indicating 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)))) + (let ((str (substring (file-modes-number-to-symbolic mode) 1))) + (unless (zerop (logand 512 mode)) + (aset mode 8 (if (zerop (logand 1 mode)) ?T ?t))) + str)) (defun tar-header-block-summarize (tar-hblock &optional mod-p) "Return a line similar to the output of `tar -vtf'." --8<-----------------------------cut here---------------end--------------->8--- In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11) of 2017-08-04 Repository revision: db5d38ddb0de83d8f920b7a128fe3fd5156fdf85