GNU bug report logs - #13575
24.1; dired-mark-sexp misparses directory contents

Previous Next

Package: emacs;

Reported by: Sean McAfee <eefacm <at> gmail.com>

Date: Mon, 28 Jan 2013 08:18:01 UTC

Severity: normal

Found in version 24.1

Fixed in version 25.1

Done: Wolfgang Jenkner <wjenkner <at> inode.at>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Wolfgang Jenkner <wjenkner <at> inode.at>
To: Sean McAfee <eefacm <at> gmail.com>
Cc: 13575 <at> debbugs.gnu.org
Subject: bug#13575: 24.1; dired-mark-sexp misparses directory contents
Date: Mon, 28 Jan 2013 20:19:17 +0100
On Mon, Jan 28 2013, Sean McAfee wrote:

> I recently wanted to mark all zero-size files in a dired buffer.  I
> found that dired-mark-sexp seemed to be just what I needed, but when I
> invoked it with the expression (= size 0), I found that it marked every
> file, even those of nonzero size.
>
> Here's a test directory I set up:
>
>   /home/mcafee/test:
>   total used in directory 28 available 102379756
>   drwxrwxr-x  2 mcafee mcafee  4096 Jan 27 18:31 .
>   drwxr-xr-x 44 mcafee mcafee 12288 Jan 27 18:31 ..
>   -rw-rw-r--  1 mcafee mcafee     8 Jan 27 18:31 bar
>   -rw-rw-r--  1 mcafee mcafee    12 Jan 27 18:31 baz
>   -rw-rw-r--  1 mcafee mcafee     4 Jan 27 18:31 foo
>
> In this directory, I ran dired-mark-sexp with the following expression,
> intended to exercise all of the available symbols:
>
> (progn (message
> "name=%s;inode=%s;s=%s;mode=%s;nlink=%s;uid=%s;gid=%s;size=%s;time=%s;sym=%s"
> name inodes mode nlink uid gid size time sym) nil)
-------^ inode s

I think you have to customize dired-listing-switches to something like
"-alis" so that inode number and block count are actually shown in the
buffer.

> Here are the messages that were produced:
> name=.;inode=0;s=0;mode=drwxrwxr-x;nlink=2;uid=mcafee;gid=2;size=0;time=
> mcafee  4096 Jan 27 18:31;sym=
> name=..;inode=0;s=0;mode=drwxr-xr-x;nlink=44;uid=mcafee;gid=44;size=0;time=
> mcafee 12288 Jan 27 18:31;sym=
[...]
> Clearly, the "time" variable includes more of the directory listing than
> it should, and "size" is incorrectly set to zero for all files, as I
> originally noticed.

That's a bug in dired-x (wrong use of the somewhat awkward
directory-listing-before-filename-regexp variable).  As a first attempt
to fix this I propose the following barely tested patch.

Wolfgang

diff --git a/lisp/dired-x.el b/lisp/dired-x.el
index a2c1303..73eebd1 100644
--- a/lisp/dired-x.el
+++ b/lisp/dired-x.el
@@ -1449,8 +1449,7 @@ to mark all zero length files."
         ;; to nil or the appropriate value, so they need not be initialized.
         ;; Moves point within the current line.
         (dired-move-to-filename)
-        (let (pos
-              (mode-len 10) ; length of mode string
+        (let ((mode-len 10) ; length of mode string
               ;; like in dired.el, but with subexpressions \1=inode, \2=s:
               (dired-re-inode-size "\\s *\\([0-9]*\\)\\s *\\([0-9]*\\) ?"))
           (beginning-of-line)
@@ -1472,22 +1471,18 @@ to mark all zero length files."
           ;; Karsten Wenger <kw <at> cis.uni-muenchen.de> fixed uid.
           (setq uid (buffer-substring (1+ (point))
                                       (progn (forward-word 1) (point))))
-          (re-search-forward directory-listing-before-filename-regexp)
-          (goto-char (match-beginning 1))
-          (forward-char -1)
-          (setq size (string-to-number
-                      (buffer-substring (save-excursion
-                                          (backward-word 1)
-                                          (setq pos (point)))
-                                        (point))))
-          (goto-char pos)
-          (backward-word 1)
+	  (re-search-forward directory-listing-before-filename-regexp)
+	  (re-search-backward directory-listing-before-filename-regexp)
+	  (forward-word 1)
+	  (save-excursion
+	    (setq size (string-to-number
+			(buffer-substring (point) (progn (backward-word 1)
+							 (point))))
+		  gid (buffer-substring (1- (point)) (progn (backward-word 1)
+							    (point)))))
           ;; if no gid is displayed, gid will be set to uid
           ;; but user will then not reference it anyway in PREDICATE.
-          (setq gid (buffer-substring (save-excursion
-                                        (forward-word 1) (point))
-                                      (point))
-                time (buffer-substring (match-beginning 1)
+          (setq time (buffer-substring (1+ (point))
                                        (1- (dired-move-to-filename)))
                 name (buffer-substring (point)
                                        (or




This bug report was last modified 10 years and 15 days ago.

Previous Next


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