Merge branch 'sg/test-rebase-editor-fix' into maint
[git] / ci / util / extract-trash-dirs.sh
1 #!/bin/sh
2
3 error () {
4         echo >&2 "error: $@"
5         exit 1
6 }
7
8 find_embedded_trash () {
9         while read -r line
10         do
11                 case "$line" in
12                 *Start\ of\ trash\ directory\ of\ \'t[0-9][0-9][0-9][0-9]-*\':*)
13                         test_name="${line#*\'}"
14                         test_name="${test_name%\'*}"
15
16                         return 0
17                 esac
18         done
19
20         return 1
21 }
22
23 extract_embedded_trash () {
24         while read -r line
25         do
26                 case "$line" in
27                 *End\ of\ trash\ directory\ of\ \'$test_name\'*)
28                         return
29                         ;;
30                 *)
31                         printf '%s\n' "$line"
32                         ;;
33                 esac
34         done
35
36         error "unexpected end of input"
37 }
38
39 # Raw logs from Linux build jobs have CRLF line endings, while OSX
40 # build jobs mostly have CRCRLF, except an odd line every now and
41 # then that has CRCRCRLF.  'base64 -d' from 'coreutils' doesn't like
42 # CRs and complains about "invalid input", so remove all CRs at the
43 # end of lines.
44 sed -e 's/\r*$//' | \
45 while find_embedded_trash
46 do
47         echo "Extracting trash directory of '$test_name'"
48
49         extract_embedded_trash |base64 -d |tar xzp
50 done