Mike Frysinger <[EMAIL PROTECTED]> wrote: > if `du -x` is given a bunch of dirs and files in the same directory, then it > fails to descend into the subdirs ... for exampe: > $ mkdir foo > $ cd foo > $ echo somestring > file > $ mkdir emptydir nonemptydir > $ cp file nonemptydir/ > > [these work] > $ du > 8 ./nonemptydir > 4 ./emptydir > 20 . > $ du * > 4 emptydir > 4 file > 8 nonemptydir > $ du -x > 8 ./nonemptydir > 4 ./emptydir > 20 . > > [this fails] > $ du -x * > 4 emptydir > 4 file > 4 nonemptydir > > tried with coreutils-6.6 and latest cvs ... coreutils-5.94 seems to work OK > though ...
Thank you for the report. That is due to a bug in gnulib's lib/fts.c. Here's the fix I've just checked in to gnulib. Below, there's also a patch for coreutils adding the mandatory test and NEWS entry. [gnulib] 2006-12-03 Jim Meyering <[EMAIL PROTECTED]> * lib/fts.c (fts_load): Don't set sp->fts_dev here, since p->fts_statp may not yet be defined. (fts_read): Instead, set it in the caller, once p->fts_statp is sure to be defined, and corresponds to a top-level directory. This bug made du -x fail. Here's the coreutils test case: http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commit;h=ba45154d8e9f Reported by Mike Frysinger. [coreutils] 2006-12-03 Jim Meyering <[EMAIL PROTECTED]> * NEWS: du --one-file-system (-x) would skip subdirectories of any directory listed as second or subsequent command line argument. * tests/du/one-file-system: New file. Test for today's fts.c fix. * tests/du/Makefile.am (TESTS): Add one-file-system. Reported by Mike Frysinger. Index: lib/fts.c =================================================================== RCS file: /sources/gnulib/gnulib/lib/fts.c,v retrieving revision 1.29 diff -u -p -r1.29 fts.c --- lib/fts.c 22 Nov 2006 23:48:30 -0000 1.29 +++ lib/fts.c 3 Dec 2006 10:22:37 -0000 @@ -516,7 +516,6 @@ fts_load (FTS *sp, register FTSENT *p) p->fts_namelen = len; } p->fts_accpath = p->fts_path = sp->fts_path; - sp->fts_dev = p->fts_statp->st_dev; } int @@ -743,9 +742,15 @@ check_for_dir: abort (); } } + sp->fts_cur = p; if (p->fts_info == FTS_D) { + /* Now that P->fts_statp is guaranteed to be valid, + if this is a command-line directory, record its + device number, to be used for FTS_XDEV. */ + if (p->fts_level == FTS_ROOTLEVEL) + sp->fts_dev = p->fts_statp->st_dev; Dprintf ((" entering: %s\n", p->fts_path)); if (! enter_dir (sp, p)) { diff --git a/NEWS b/NEWS index 3493041..92de634 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,11 @@ GNU coreutils NEWS -*- outline -*- * Noteworthy changes in release 6.7-pre (????-??-??) [?] +** Bug fixes + + du --one-file-system (-x) would skip subdirectories of any directory + listed as second or subsequent command line argument. + * Noteworthy changes in release 6.6 (2006-11-22) [stable] diff --git a/tests/du/Makefile.am b/tests/du/Makefile.am index e766eb5..e547b6b 100644 --- a/tests/du/Makefile.am +++ b/tests/du/Makefile.am @@ -21,6 +21,7 @@ AUTOMAKE_OPTIONS = 1.4 gnits TESTS = \ + one-file-system \ inacc-dest \ long-from-unreadable \ long-sloop \ diff --git a/tests/du/one-file-system b/tests/du/one-file-system new file mode 100755 index 0000000..b595dc6 --- /dev/null +++ b/tests/du/one-file-system @@ -0,0 +1,61 @@ +#!/bin/sh +# Test for a bug in fts's handling of FTS_XDEV, the flag behind +# du's --one-file-system (-x) option. + +# Copyright (C) 2006 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + +if test "$VERBOSE" = yes; then + set -x + du --version +fi + +. $srcdir/../envvar-check + +pwd=`pwd` +t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ +trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 +trap '(exit $?); exit $?' 1 2 13 15 + +framework_failure=0 +mkdir -p $tmp || framework_failure=1 +cd $tmp || framework_failure=1 +mkdir -p b/c y/z || framework_failure=1 + +if test $framework_failure = 1; then + echo "$0: failure in testing framework" 1>&2 + (exit 1); exit 1 +fi + +fail=0 + +# Due to a used-uninitialized variable, the "du -x" from coreutils-6.6 +# would not traverse into second and subsequent directories listed +# on the command line. +du -ax b y > t || fail=1 +sed 's/^[0-9][0-9]* //' t > out +cat <<\EOF > exp || fail=1 +b/c +b +y/z +y +EOF + +cmp out exp || fail=1 +test $fail = 1 && diff out exp 2> /dev/null + +(exit $fail); exit $fail