Skip to content

Commit ea94de3

Browse files
authored
FEAT: always cleanup temporary directory
1 parent 6e69b40 commit ea94de3

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

overlay/ExportToS3.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
#!/bin/bash
22
set -euo pipefail
33

4+
TMP_DIR=$(mktemp -d)
5+
6+
cleanup() {
7+
local exit_code=$? # 保存脚本退出码
8+
echo "Cleaning up temporary directory: $TMP_DIR"
9+
rm -rf "$TMP_DIR"
10+
exit $exit_code # 保持原始退出状态
11+
}
12+
13+
# 无论成功或失败都会触发
14+
trap cleanup EXIT
15+
416
# 配置变量
517
GITHUB_ORGS=${GITHUB_ORGS:-""}
618
S3_BUCKET=${S3_BUCKET:-""}
7-
TMP_DIR=$(mktemp -d)
819
SSH_KEY_PATH="${SSH_KEY_PATH:-}"
920

1021
# 检查必需环境变量
@@ -86,6 +97,3 @@ for FILE in "$TMP_DIR"/*.tar.xz "$TMP_DIR"/*/*.tar.xz; do
8697
done
8798

8899
echo "All repositories processed successfully."
89-
90-
# 清理临时目录
91-
rm -rf "$TMP_DIR"

0 commit comments

Comments
 (0)