Skip to content

Commit 2e050a3

Browse files
committed
handle first upload
Signed-off-by: Andrew Duffy <andrew@a10y.dev>
1 parent 086ea02 commit 2e050a3

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

scripts/cat-s3.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@ local_concatenated=$(mktemp)
1212
n_failures=0
1313

1414
while (( n_failures < 100 )); do
15-
current_etag=$(aws s3api head-object --bucket "$bucket" --key "$key" --query ETag --output text)
15+
current_etag=$(aws s3api head-object --bucket "$bucket" --key "$key" --query ETag --output text 2>/dev/null) || {
16+
# File doesn't exist yet, create it fresh
17+
echo "File does not exist in S3, creating new file."
18+
if [[ "$key" =~ \.gz$ ]]; then
19+
gzip -c "$local_file_to_concatenate" > "$local_concatenated"
20+
else
21+
cp "$local_file_to_concatenate" "$local_concatenated"
22+
fi
23+
aws s3api put-object --bucket "$bucket" --key "$key" --body "$local_concatenated"
24+
echo "File created and uploaded successfully."
25+
exit 0
26+
}
1627
if [[ "$current_etag" == "null" ]]; then
1728
echo "Failed to retrieve ETag. Exiting."
1829
exit 1
@@ -32,7 +43,7 @@ while (( n_failures < 100 )); do
3243
gzip -c "$local_decompressed_concat" > "$local_concatenated"
3344
rm "$local_decompressed" "$local_decompressed_concat"
3445
else
35-
cat $local_copy $local_file_to_concatenate > $local_concatenated
46+
cat "$local_copy" "$local_file_to_concatenate" > "$local_concatenated"
3647
fi
3748

3849

0 commit comments

Comments
 (0)