Files
git/cpio.sh
Johannes Schindelin b9dcb2cbe5 Fix cpio for CR/LF line endings
Under certain circumstances (I did not find out the complete
details, but it happens when running the tests), the filterdirs()
function in cpio outputs CR/LF.  Since tar does not like that,
the command failed.

So strip out all CRs when filtering the directories.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2007-09-03 19:55:09 +01:00

54 lines
757 B
Bash

#!/bin/sh
#
# Emulates some cpio behavior using GNU tar
die() {
echo >&2 "$@"
exit 1
}
null=
while test $# -gt 0; do
case "$1" in
-0) null=--null;;
-o) mode=o;;
-iuv) ;;
-pumd|-pumdl)
mode=p
dir="$2"
shift
;;
*) die "cpio emulation supports only -0, -o, -iuv, -pumdl";;
esac
shift
done
filterdirs() {
while read f; do
if test -d "$f"; then
# list only empty directories
if test -z "$(ls -A "$f")"; then
echo "$f"
fi
else
echo "$f"
fi
done
}
case $mode in
o)
tar --create --file=- $null --files-from=-
;;
p)
test -z "$null" || die "cpio: cannot use -0 in pass-through mode"
filterdirs |
tr -d '\r' |
tar --create --file=- --files-from=- |
tar --extract --directory="$dir" --file=-
;;
*)
tar xvf -
esac