Skip to content

Add trap to ensure temp file cleanup in SRI script#266

Merged
myoshi2891 merged 3 commits into
mainfrom
dev-from-macmini
Feb 11, 2026
Merged

Add trap to ensure temp file cleanup in SRI script#266
myoshi2891 merged 3 commits into
mainfrom
dev-from-macmini

Conversation

@myoshi2891

Copy link
Copy Markdown
Owner

updated calc_sri_fix.sh to include a trap that ensures temporary files are cleaned up even if the script exits early or encounters an error.

@coderabbitai

coderabbitai Bot commented Feb 11, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Summary by CodeRabbit

  • 新機能

    • ダウンロードしたコンテンツの SHA-384(Base64 表記)ハッシュを出力するようになりました(" sha384-" 形式)。
  • 改善

    • 終了経路にかかわらず一時ファイルが確実に削除されるようクリーンアップ処理を強化しました。
    • 冗長な手動クリーンアップを整理して信頼性を向上しました。

Walkthrough

シェルスクリプト calc_sri_fix.sh に対し、一時ファイルの削除処理をトラップで一元化する変更と、ダウンロード内容の SHA‑384(base64)ハッシュを算出して <url> sha384-<base64_hash> を出力する処理が追加されました。エラーパス内の 2 件の明示的な rm -f は削除された一方、関数末尾の明示的な rm -f は残っています。

Changes

Cohort / File(s) Summary
Script: cleanup & hashing
calc_sri_fix.sh
trap を追加して RETURN 時に一時ファイルを削除するハンドラを登録。エラーパス内の 2 つの明示的な rm -f を削除。ダウンロード内容の SHA‑384(base64)ハッシュを計算し "<url> sha384-<base64_hash>" を出力。関数末尾の明示的な rm -f "$temp_file" は残存。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰🔧 一時ファイル ぽいっ と飛ばし
トラップでキレイに片付ける
ハッシュ歌えば sha384 の調べ
URL と紐づく歌をひとつ
スクリプトは軽やかに跳ねる

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed プルリクエストのタイトルは、変更内容の主要な目的である一時ファイルのクリーンアップを確実にするためのtrapの追加を明確に要約しています。
Description check ✅ Passed 説明はchangesetの主要な目的に関連しており、trapを追加してスクリプトの早期終了またはエラー時に一時ファイルがクリーンアップされることを説明しています。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev-from-macmini

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
calc_sri_fix.sh (1)

24-24: 🛠️ Refactor suggestion | 🟠 Major

冗長な rm -f — トラップに任せるべきです。

Line 8 の trap ... RETURN が関数終了時に自動的にクリーンアップするため、この明示的な rm -f は不要です。PR の目的(クリーンアップをトラップに一元化する)と矛盾しており、削除すべきです。

♻️ 修正案
     hash=$(openssl dgst -sha384 -binary < "$temp_file" | openssl base64 -A)
     echo "$url sha384-$hash"
-    rm -f "$temp_file"
 }

@coderabbitai

coderabbitai Bot commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

Note

Docstrings generation - SUCCESS
Generated docstrings for this pull request at #267

Docstrings generation was requested by @myoshi2891.

* #266 (comment)

The following files were modified:

* `calc_sri_fix.sh`

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
calc_sri_fix.sh (1)

25-25: 🛠️ Refactor suggestion | 🟠 Major

冗長な rm -f を削除してください。

Line 9 の trap ... RETURN が関数終了時に自動でクリーンアップを行うため、Line 25 の明示的な rm -f は不要です。二重削除自体は無害ですが、トラップによる一元管理という意図と矛盾し、メンテナンス時に混乱を招きます。

♻️ 修正案
     hash=$(openssl dgst -sha384 -binary < "$temp_file" | openssl base64 -A)
     echo "$url sha384-$hash"
-    rm -f "$temp_file"
 }
🤖 Fix all issues with AI agents
In `@calc_sri_fix.sh`:
- Around line 7-9: 関数内でグローバルを汚染しているので、変数 url と temp_file をローカル化してください(宣言する名前:
url, temp_file);さらにトラップの対象ファイルが将来の並列/入れ子呼び出しで変わらないように、トラップ登録時に temp_file
の現在値を固定する形式に変更してください(参照箇所: 変数 url, 変数 temp_file, 現在の trap 'rm -f "$temp_file"'
RETURN)。

Comment thread calc_sri_fix.sh
Comment on lines 7 to +9
url="$1"
temp_file=$(mktemp)
trap 'rm -f "$temp_file"' RETURN

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

urltemp_filelocal で宣言してください。

関数内で local を使わずに変数を代入しているため、グローバルスコープを汚染します。trap 内の $temp_file はトラップ発火時に展開されるため、もし将来的に並列呼び出しや入れ子呼び出しが発生した場合、意図しないファイルを削除するリスクがあります。

♻️ 修正案
 calculate_sri() {
-    url="$1"
-    temp_file=$(mktemp)
+    local url="$1"
+    local temp_file
+    temp_file=$(mktemp)
     trap 'rm -f "$temp_file"' RETURN
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
url="$1"
temp_file=$(mktemp)
trap 'rm -f "$temp_file"' RETURN
local url="$1"
local temp_file
temp_file=$(mktemp)
trap 'rm -f "$temp_file"' RETURN
🤖 Prompt for AI Agents
In `@calc_sri_fix.sh` around lines 7 - 9, 関数内でグローバルを汚染しているので、変数 url と temp_file
をローカル化してください(宣言する名前: url,
temp_file);さらにトラップの対象ファイルが将来の並列/入れ子呼び出しで変わらないように、トラップ登録時に temp_file
の現在値を固定する形式に変更してください(参照箇所: 変数 url, 変数 temp_file, 現在の trap 'rm -f "$temp_file"'
RETURN)。

@myoshi2891 myoshi2891 merged commit 2c5a9b8 into main Feb 11, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant