@@ -3,37 +3,38 @@ set -o pipefail -o errexit
33
44bsdtar=" $1 " ;
55deduplicate=" $2 " ;
6- shift 2;
6+ readonly awk=" $3 "
7+ shift 3;
78
89# Deduplication requested, use this complex pipeline to deduplicate.
910if [[ " $deduplicate " == " True" ]]; then
1011
1112 mtree=$( mktemp)
1213
13- # List files in all archives and append to single column mtree.
14- for arg in " $@ " ; do
14+ # List files in all archives and append to single column mtree.
15+ for arg in " $@ " ; do
1516 if [[ " $arg " == " @" * ]]; then
1617 " $bsdtar " -tf " ${arg: 1} " >> " $mtree "
1718 fi
1819 done
1920
2021 # There not a lot happening here but there is still too many implicit knowledge.
21- #
22+ #
2223 # When we run bsdtar, we ask for it to prompt every entry, in the same order we created above, the mtree.
2324 # See: https://github.com/libarchive/libarchive/blob/f745a848d7a81758cd9fcd49d7fd45caeebe1c3d/tar/write.c#L683
24- #
25+ #
2526 # For every prompt, therefore entry, we have write 31 bytes of data, one of which has to be either 'Y' or 'N'.
2627 # And the reason for it is that since we are not TTY and pretending to be one, we can't interleave write calls
2728 # so we have to interleave it by filling up the buffer with 31 bytes of 'Y' or 'N'.
2829 # See: https://github.com/libarchive/libarchive/blob/f745a848d7a81758cd9fcd49d7fd45caeebe1c3d/tar/util.c#L240
2930 # See: https://github.com/libarchive/libarchive/blob/f745a848d7a81758cd9fcd49d7fd45caeebe1c3d/tar/util.c#L216
30- #
31+ #
3132 # To match the extraction behavior of tar itself, we want to preserve only the final occurrence of each file
3233 # and directory in the archive. To do this, we iterate over all the entries twice. The first pass computes the
3334 # number of occurrences of each path, and the second pass determines whether each entry is the final (or only)
3435 # occurrence of that path.
3536
36- $bsdtar --confirmation " $@ " 2< <( awk ' {
37+ $bsdtar --confirmation " $@ " 2< <( " ${ awk} " ' {
3738 count[$1]++;
3839 files[NR] = $1
3940 }
@@ -50,7 +51,7 @@ if [[ "$deduplicate" == "True" ]]; then
5051 }
5152 }' " $mtree " )
5253 rm " $mtree "
53- else
54+ else
5455 # No deduplication, business as usual
5556 $bsdtar " $@ "
56- fi
57+ fi
0 commit comments