Avoid spawning 'ls' for each directory that is passed to the cpio emulator.

We assume that the file names are passed in using find -depth so that a
directory is listed after its contents.
This commit is contained in:
Johannes Sixt
2007-08-17 15:14:57 +02:00
parent 94be0afa31
commit 009ab81675

14
cpio.sh
View File

@@ -24,16 +24,24 @@ while test $# -gt 0; do
shift
done
prev=
filterdirs() {
while read f; do
if test -d "$f"; then
# list only empty directories
if test -z "$(ls -A "$f")"; then
echo "$f"
fi
# here we assume that directories are listed after
# its files (aka 'find -depth'), hence, a directory
# that is not empty will be a leading sub-string
# of the preceding entry
case "$prev" in
"$f"/* ) ;;
*) echo "$f";;
esac
else
echo "$f"
fi
prev="$f"
done
}