Skip to content

Commit 9ce62b6

Browse files
committed
Improve select_file error handling
When tar/zip are unhappy with their inputs, they will yield no list items, and we want to treat that as fatal. When the list is empty or the grep fails to find something, we want to explain which case happened before dying.
1 parent 91f4616 commit 9ce62b6

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

gh-program-downloader

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,27 @@ download_artifact() {
134134
}
135135

136136
select_file() {
137-
(
138-
if [ -n "$file_re" ]; then
139-
grep -E "$file_re"
137+
list=$(mktemp)
138+
cat - > "$list"
139+
if [ ! -s "$list" ]; then
140+
echo "No files in archive" >&2
141+
false
142+
fi
143+
if [ -n "$file_re" ]; then
144+
result=$(
145+
grep -E "$file_re" "$list" | tail -1
146+
)
147+
rm -f "$list"
148+
if [ -n "$result" ]; then
149+
echo "$result"
140150
else
141-
cat -
151+
echo "file_re ($file_re) did not match any files in archive" >&2
152+
false
142153
fi
143-
) | tail -1
154+
else
155+
tail -1 "$list"
156+
rm -f "$list"
157+
fi
144158
}
145159

146160
strip_zip_file_size_date_and_time_from_directory_listing() {

0 commit comments

Comments
 (0)