Skip to content

Commit 3b84b37

Browse files
delete folders
1 parent d006a24 commit 3b84b37

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

.github/workflows/interop.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ jobs:
1111
id-token: write
1212
contents: read
1313
env:
14-
LOGNAME: ${{ needs.config.outputs.logname }}
1514
BUCKET: "quic-interop-runner"
15+
RETENTION_DAYS: "3"
1616
steps:
1717
- uses: actions/checkout@v3
1818
- uses: actions/setup-python@v4
@@ -26,7 +26,17 @@ jobs:
2626
B2_APPLICATION_KEY: ${{ secrets.BACKBLAZE_APPLICATION_KEY }}
2727
- name: upload a file
2828
run: |
29-
b2 ls --long ${{ env.BUCKET }}
30-
b2 ls --long ${{ env.BUCKET}} | awk -v days=3 -v today=$(date +%s) '$1=="upload" && (today - $3) > days*86400 {print $4}'
31-
29+
threshold_time=$((($(date +%s) * 1000) - (${{ env.RETENTION_DAYS }} * 24 * 60 * 60 * 1000)))
30+
old_files=$(b2 ls --json ${{ env.BUCKET}} | jq -r ".[] | select(.uploadTimestamp > $threshold_time)")
31+
echo "Deleting files:"
32+
echo $old_files | jq ".fileName"
33+
# Now delete them
34+
echo $old_files | jq -r ".fileName" | while read -r filename; do
35+
dir_name="${filename%%/*}"
36+
echo "Deleting $dir_name"
37+
# see https://github.com/Backblaze/B2_Command_Line_Tool/issues/495#issuecomment-413932585
38+
mkdir empty # create an empty directory
39+
b2 sync --delete --allowEmptySource empty b2://${{ env.BUCKET }}/"$dir_name"
40+
rmdir empty
41+
done
3242

0 commit comments

Comments
 (0)