emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: master 3a284e5: Combine archive-int-to-mode and tar-grind-file-mode


From: Stefan Monnier
Subject: Re: master 3a284e5: Combine archive-int-to-mode and tar-grind-file-mode
Date: Thu, 14 May 2020 15:51:05 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> +(defun file-modes-number-to-symbolic (mode)
> +  (string
> +   (if (zerop (logand  8192 mode))
> +       (if (zerop (logand 16384 mode)) ?- ?d)
> +     ?c) ; completeness

BTW, I was looking at how to get rid of `tar-grind-file-mode` and along
the way I saw that this first char is really representing the file type
and there is no real standard for how a "modes" number can represent the
file type.  IOW the 8192/16484 above are fairly arbitrary (I suspect they
correspond to what happens to be used in `.zip` files and probably
won't match what's used in any other circumstance, e.g. they don't match
what Git uses, IIUC).

How 'bout the patch below?


        Stefan


diff --git a/lisp/arc-mode.el b/lisp/arc-mode.el
index 6ce64fe24b3..82a79af8931 100644
--- a/lisp/arc-mode.el
+++ b/lisp/arc-mode.el
@@ -563,8 +563,13 @@ archive-l-e
                      (aref str (- len i)))))
     result))
 
-(define-obsolete-function-alias 'archive-int-to-mode
-  'file-modes-number-to-symbolic "28.1")
+(defun archive-int-to-mode (mode)
+  ;; FIXME: Make this obsolete.  For this, we will need to clarify
+  ;; where those 8192/16384 come from and what to do about them.
+  (file-modes-number-to-symbolic
+   mode (if (zerop (logand  8192 mode))
+            (if (zerop (logand 16384 mode)) ?- ?d)
+          ?c)))
 
 (defun archive-calc-mode (oldmode newmode)
   "From the integer OLDMODE and the string NEWMODE calculate a new file mode.
@@ -626,7 +631,8 @@ archive-get-descr
        (let ((item (aref archive-files no)))
          (if (and (archive--file-desc-p item)
                   (let ((mode (archive--file-desc-mode item)))
-                    (zerop (logand 16384 mode))))
+                    ;; FIXME: Why 16384?  See comment in archive-int-to-mode.
+                    (or (null mode) (zerop (logand 16384 mode)))))
              item
            (if (not noerror)
                (user-error "Entry is not a regular member of the archive"))))
@@ -2119,7 +2125,6 @@ archive-7z-write-file-member
 ;; not the GNU nor the BSD extensions.  As it turns out, this is sufficient
 ;; for .deb packages.
 
-(autoload 'tar-grind-file-mode "tar-mode")
 
 (defconst archive-ar-file-header-re
   "\\(.\\{16\\}\\)\\([ 0-9]\\{12\\}\\)\\([ 0-9]\\{6\\}\\)\\([ 
0-9]\\{6\\}\\)\\([ 0-7]\\{8\\}\\)\\([ 0-9]\\{10\\}\\)`\n")
diff --git a/lisp/files.el b/lisp/files.el
index dba704f7a4b..cfbe085f9c1 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -441,6 +441,7 @@ auto-save-visited-mode
            #'save-some-buffers :no-prompt
            (lambda ()
              (and buffer-file-name
+                  auto-save-visited-mode
                   (not (and buffer-auto-save-file-name
                             auto-save-visited-file-name))))))))
 
@@ -7552,11 +7553,14 @@ file-modes-rights-to-number
              op char-right)))
     num-rights))
 
-(defun file-modes-number-to-symbolic (mode)
+(defun file-modes-number-to-symbolic (mode &optional filetype)
+  "Return a string describing a 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 replace
+the leading `-' char."
   (string
-   (if (zerop (logand  8192 mode))
-       (if (zerop (logand 16384 mode)) ?- ?d)
-     ?c) ; completeness
+   (or filetype ?-)
    (if (zerop (logand   256 mode)) ?- ?r)
    (if (zerop (logand   128 mode)) ?- ?w)
    (if (zerop (logand    64 mode))
diff --git a/lisp/tar-mode.el b/lisp/tar-mode.el
index 73978ffc4a7..75ffb5647e1 100644
--- a/lisp/tar-mode.el
+++ b/lisp/tar-mode.el
@@ -482,6 +482,7 @@ tar-grind-file-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------'."
+  (declare (obsolete file-modes-number-to-symbolic "28.1"))
   (substring (file-modes-number-to-symbolic mode) 1))
 
 (defun tar-header-block-summarize (tar-hblock &optional mod-p)
@@ -497,25 +498,26 @@ tar-header-block-summarize
        ;; (ck (tar-header-checksum tar-hblock))
        (type (tar-header-link-type tar-hblock))
        (link-name (tar-header-link-name tar-hblock)))
-    (format "%c%c%s %7s/%-7s %7s%s %s%s"
+    (format "%c%s %7s/%-7s %7s%s %s%s"
            (if mod-p ?* ? )
-           (cond ((or (eq type nil) (eq type 0)) ?-)
-                 ((eq type 1) ?h)      ; link
-                 ((eq type 2) ?l)      ; symlink
-                 ((eq type 3) ?c)      ; char special
-                 ((eq type 4) ?b)      ; block special
-                 ((eq type 5) ?d)      ; directory
-                 ((eq type 6) ?p)      ; FIFO/pipe
-                 ((eq type 20) ?*)     ; directory listing
-                 ((eq type 28) ?L)     ; next has longname
-                 ((eq type 29) ?M)     ; multivolume continuation
-                 ((eq type 35) ?S)     ; sparse
-                 ((eq type 38) ?V)     ; volume header
-                 ((eq type 55) ?H)     ; pax global extended header
-                 ((eq type 72) ?X)     ; pax extended header
-                 (t ?\s)
-                 )
-           (tar-grind-file-mode mode)
+           (file-modes-number-to-symbolic
+            (tar-grind-file-mode mode)
+            (cond ((or (eq type nil) (eq type 0)) ?-)
+                  ((eq type 1) ?h)     ; link
+                  ((eq type 2) ?l)     ; symlink
+                  ((eq type 3) ?c)     ; char special
+                  ((eq type 4) ?b)     ; block special
+                  ((eq type 5) ?d)     ; directory
+                  ((eq type 6) ?p)     ; FIFO/pipe
+                  ((eq type 20) ?*)    ; directory listing
+                  ((eq type 28) ?L)    ; next has longname
+                  ((eq type 29) ?M)    ; multivolume continuation
+                  ((eq type 35) ?S)    ; sparse
+                  ((eq type 38) ?V)    ; volume header
+                  ((eq type 55) ?H)    ; pax global extended header
+                  ((eq type 72) ?X)    ; pax extended header
+                  (t ?\s)
+                  ))
            (if (= 0 (length uname)) uid uname)
            (if (= 0 (length gname)) gid gname)
            size




reply via email to

[Prev in Thread] Current Thread [Next in Thread]