Skip to content

Commit

Permalink
delete folders
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Oct 7, 2023
1 parent d006a24 commit 3b84b37
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/interop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
id-token: write
contents: read
env:
LOGNAME: ${{ needs.config.outputs.logname }}
BUCKET: "quic-interop-runner"
RETENTION_DAYS: "3"
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
Expand All @@ -26,7 +26,17 @@ jobs:
B2_APPLICATION_KEY: ${{ secrets.BACKBLAZE_APPLICATION_KEY }}
- name: upload a file
run: |
b2 ls --long ${{ env.BUCKET }}
b2 ls --long ${{ env.BUCKET}} | awk -v days=3 -v today=$(date +%s) '$1=="upload" && (today - $3) > days*86400 {print $4}'
threshold_time=$((($(date +%s) * 1000) - (${{ env.RETENTION_DAYS }} * 24 * 60 * 60 * 1000)))
old_files=$(b2 ls --json ${{ env.BUCKET}} | jq -r ".[] | select(.uploadTimestamp > $threshold_time)")
echo "Deleting files:"
echo $old_files | jq ".fileName"
# Now delete them
echo $old_files | jq -r ".fileName" | while read -r filename; do
dir_name="${filename%%/*}"
echo "Deleting $dir_name"
# see https://github.com/Backblaze/B2_Command_Line_Tool/issues/495#issuecomment-413932585
mkdir empty # create an empty directory
b2 sync --delete --allowEmptySource empty b2://${{ env.BUCKET }}/"$dir_name"
rmdir empty
done

0 comments on commit 3b84b37

Please sign in to comment.