Skip to content

Conversation

@SigureMo
Copy link
Contributor

开新终端经常出现如下报错:

/Users/nyakku/.zshrc:142: file exists: /tmp/meowda-init-tmp.sh

大概率是多个 shell 之间冲突导致的,添加随机数试一下能否避免

Copilot AI review requested due to automatic review settings December 14, 2025 17:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a file conflict issue when opening multiple shell terminals simultaneously. The error "file exists: /tmp/meowda-init-tmp.sh" occurs because multiple shell processes try to create the same temporary file during initialization. The fix adds a random suffix using the $RANDOM variable to make each temporary file unique.

Key Changes:

  • Modified the temporary script filename from a static name to include $RANDOM variable for uniqueness

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

r#"
# {meowda_init_comment}
MEOWDA_TMP_SCRIPT="/tmp/meowda-init-tmp.sh"
MEOWDA_TMP_SCRIPT="/tmp/meowda-init-tmp-$RANDOM.sh"
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

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

Using $RANDOM for temporary file naming has several issues:

  1. Shell compatibility: $RANDOM is specific to Bash and Zsh, but won't work in POSIX sh or other shells like dash, which may cause the initialization to fail on some systems.

  2. Security concern: $RANDOM generates predictable values (0-32767), making it vulnerable to race conditions and potential security issues in /tmp directories.

  3. Better alternative: Use the mktemp command instead, which is POSIX-compliant, generates cryptographically secure unique filenames, and automatically handles race conditions.

Consider changing this line to use mktemp:
MEOWDA_TMP_SCRIPT="$(mktemp /tmp/meowda-init-tmp.XXXXXX.sh)"

This ensures cross-shell compatibility and eliminates the race condition security concern.

Suggested change
MEOWDA_TMP_SCRIPT="/tmp/meowda-init-tmp-$RANDOM.sh"
MEOWDA_TMP_SCRIPT="$(mktemp /tmp/meowda-init-tmp.XXXXXX.sh)"

Copilot uses AI. Check for mistakes.
@SigureMo SigureMo merged commit 1bc61bf into main Dec 14, 2025
22 checks passed
@SigureMo SigureMo deleted the add-random-suffix branch December 14, 2025 17:47
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.

2 participants