Work around failures due to bogus quoting of ^ and {}.
[git/platforms.git] / cpio.sh
blob2816e34851903f32fc2be980990087f59dbb1896
1 #!/bin/sh
3 # Emulates some cpio behavior using GNU tar
5 die() {
6 echo >&2 "$@"
7 exit 1
10 null=
12 while test $# -gt 0; do
13 case "$1" in
14 -0) null=--null;;
15 -o) mode=o;;
16 -iuv) ;;
17 -pumd|-pumdl)
18 mode=p
19 dir="$2"
20 shift
22 *) die "cpio emulation supports only -0, -o, -iuv, -pumdl";;
23 esac
24 shift
25 done
27 filterdirs() {
28 while read f; do
29 if test -d "$f"; then
30 # list only empty directories
31 if test -z "$(ls -A "$f")"; then
32 echo "$f"
34 else
35 echo "$f"
37 done
40 case $mode in
42 tar --create --file=- $null --files-from=-
45 test -z "$null" || die "cpio: cannot use -0 in pass-through mode"
46 filterdirs |
47 tar --create --file=- --files-from=- |
48 tar --extract --directory="$dir" --file=-
51 tar xvf -
52 esac