Skip to content

Commit e75e308

Browse files
danielbodartclaude
andcommitted
Atomic script replacement in update to prevent bash read corruption
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 514dfc9 commit e75e308

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

dist/linux/capsper-update.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,14 @@ main() {
192192
|| [ -f "$release_dir/bin/capsper" ] \
193193
|| die "Extracted release is missing capsper binaries"
194194

195-
# Update top-level scripts from staged release
195+
# Update top-level scripts from staged release.
196+
# Use cp-to-temp + mv (rename) so the running script keeps its old inode —
197+
# a plain `cp` overwrites in-place, which corrupts bash's read position.
196198
for script in capsper-update.sh capsper-apply-update.sh capsper-rollback.sh; do
197199
if [ -f "$release_dir/$script" ]; then
198-
cp "$release_dir/$script" "$INSTALL_DIR/"
199-
chmod +x "$INSTALL_DIR/$script"
200+
cp "$release_dir/$script" "$INSTALL_DIR/$script.tmp"
201+
chmod +x "$INSTALL_DIR/$script.tmp"
202+
mv -f "$INSTALL_DIR/$script.tmp" "$INSTALL_DIR/$script"
200203
fi
201204
done
202205

0 commit comments

Comments
 (0)