-
Notifications
You must be signed in to change notification settings - Fork 0
fix: restore agent mirror flexibility #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,19 @@ | |
| set -euo pipefail | ||
|
|
||
| quiet=0 | ||
| if [[ "${1:-}" == "--quiet" ]]; then | ||
| quiet=1 | ||
| fi | ||
| require_hardlink=0 | ||
|
|
||
| for arg in "$@"; do | ||
| case "$arg" in | ||
| --quiet) quiet=1 ;; | ||
| --require-hardlink) require_hardlink=1 ;; | ||
| *) | ||
| echo "error: unknown arg: $arg" >&2 | ||
| echo "usage: $0 [--quiet] [--require-hardlink]" >&2 | ||
| exit 64 | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| repo_root="$({ | ||
| cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd | ||
|
|
@@ -54,21 +64,40 @@ link_count_of() { | |
| return 1 | ||
| } | ||
|
|
||
| link_or_copy() { | ||
| link_or_symlink_or_copy() { | ||
| local dst="$1" | ||
|
|
||
| # Remove symlinks explicitly; ln -f replaces regular files but not all symlinks reliably. | ||
| if [[ -L "$dst" ]]; then | ||
| rm -f "$dst" | ||
| fi | ||
|
|
||
| # 1) Prefer hardlink. | ||
| if ln -f "$src" "$dst" 2>/dev/null; then | ||
| return 0 | ||
| fi | ||
|
|
||
| # If hardlinking fails (e.g., cross-filesystem), keep content correct but warn. | ||
| # 2) Fallback to symlink (works across filesystems). | ||
| local rel | ||
| rel="$(python - <<'PY' | ||
| import os | ||
| import sys | ||
| src = sys.argv[1] | ||
| dst = sys.argv[2] | ||
| print(os.path.relpath(src, os.path.dirname(dst))) | ||
| PY | ||
| "$src" "$dst" 2>/dev/null || true)" | ||
|
|
||
| if [[ -n "$rel" ]]; then | ||
| if ln -sf "$rel" "$dst" 2>/dev/null; then | ||
| echo "warning: could not hardlink $dst; created symlink instead" >&2 | ||
| return 0 | ||
| fi | ||
| fi | ||
|
|
||
| # 3) Last resort: copy contents. | ||
| cp -f "$src" "$dst" | ||
| echo "warning: could not hardlink $dst; copied contents instead" >&2 | ||
| echo "warning: could not hardlink or symlink $dst; copied contents instead" >&2 | ||
| return 0 | ||
|
Comment on lines
+93
to
101
|
||
| } | ||
|
|
||
|
|
@@ -91,17 +120,21 @@ is_hardlinked_pair() { | |
| ensure_pair() { | ||
| local dst="$1" | ||
|
|
||
| link_or_copy "$dst" | ||
| link_or_symlink_or_copy "$dst" | ||
|
|
||
| if ! cmp -s "$src" "$dst"; then | ||
| echo "error: $dst does not match $src" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! is_hardlinked_pair "$src" "$dst"; then | ||
| echo "error: $dst is not hardlinked to $src (same contents, different inode)" >&2 | ||
| echo "hint: ensure both files are on the same filesystem; rerun scripts/ensure_agent_hardlinks.sh" >&2 | ||
| exit 2 | ||
| if [[ "$require_hardlink" -eq 1 ]]; then | ||
| echo "error: $dst is not hardlinked to $src (same contents, different inode)" >&2 | ||
| echo "hint: ensure both files are on the same filesystem; rerun scripts/ensure_agent_hardlinks.sh" >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| echo "warning: $dst is not hardlinked to $src (content matches)" >&2 | ||
| fi | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,9 +2,19 @@ | |||||
| set -euo pipefail | ||||||
|
|
||||||
| quiet=0 | ||||||
| if [[ "${1:-}" == "--quiet" ]]; then | ||||||
| quiet=1 | ||||||
| fi | ||||||
| require_hardlink=0 | ||||||
|
|
||||||
| for arg in "$@"; do | ||||||
| case "$arg" in | ||||||
| --quiet) quiet=1 ;; | ||||||
| --require-hardlink) require_hardlink=1 ;; | ||||||
| *) | ||||||
| echo "error: unknown arg: $arg" >&2 | ||||||
| echo "usage: $0 [--quiet] [--require-hardlink]" >&2 | ||||||
| exit 64 | ||||||
| ;; | ||||||
| esac | ||||||
| done | ||||||
|
|
||||||
| repo_root="$({ | ||||||
| cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd | ||||||
|
|
@@ -35,4 +45,8 @@ if [[ "$quiet" -eq 0 ]]; then | |||||
| fi | ||||||
| fi | ||||||
|
|
||||||
| "$repo_root/scripts/ensure_agent_hardlinks.sh" ${quiet:+--quiet} | ||||||
| ensure_args=() | ||||||
| if [[ "$quiet" -eq 1 ]]; then ensure_args+=(--quiet); fi | ||||||
| if [[ "$require_hardlink" -eq 1 ]]; then ensure_args+=(--require-hardlink); fi | ||||||
|
|
||||||
| "$repo_root/scripts/ensure_agent_hardlinks.sh" "${ensure_args[@]}" | ||||||
|
||||||
| "$repo_root/scripts/ensure_agent_hardlinks.sh" "${ensure_args[@]}" | |
| "$repo_root/scripts/ensure_agent_hardlinks.sh" ${ensure_args[@]+"${ensure_args[@]}"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Python heredoc is missing the arguments to the Python interpreter. The command should pass arguments to the Python script, but line 89 starts with
"$src" "$dst"which will be interpreted as shell commands rather than arguments to Python.The Python script expects
sys.argv[1]andsys.argv[2], but these won't be available. This should be:rel="$(python - "$src" "$dst" <<'PY'This ensures the arguments are passed to Python correctly.