Skip to content

Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.

fix(install): keep target path in sync

Samir Hossainsf65929f952ab
diff --git a/install.sh b/install.sh
index 7daa045..9f406dd 100755
--- a/install.sh
+++ b/install.sh
@@ -11,6 +11,10 @@ INSTALL_DIR="/usr/local/bin"
BIN_NAME="moviebox-tui"
APP_PATH="$INSTALL_DIR/$BIN_NAME"
+sync_app_path() {
+ APP_PATH="$INSTALL_DIR/$BIN_NAME"
+}
+
command -v curl >/dev/null 2>&1 || log_err "curl is required but not installed. Please install it."
command -v tar >/dev/null 2>&1 || log_err "tar is required but not installed. Please install it."
@@ -45,6 +49,7 @@ elif [ -n "${PREFIX:-}" ] && [[ "$PREFIX" == *com.termux* ]]; then
if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
FILE="MovieBox_Termux_arm64.tar.gz"
INSTALL_DIR="$PREFIX/bin"
+ sync_app_path
else
log_err "Unsupported Termux architecture ($ARCH). Only arm64/aarch64 is natively hosted. Please use cargo install."
fi
@@ -101,13 +106,13 @@ elif command -v sudo >/dev/null 2>&1; then
else
log_warn "Sudo access failed or was cancelled. Falling back to local installation..."
INSTALL_DIR="$HOME/.local/bin"
- APP_PATH="$INSTALL_DIR/$BIN_NAME"
+ sync_app_path
mkdir -p "$INSTALL_DIR"
install -m 755 "$TMP_DIR/$BIN_NAME" "$APP_PATH"
fi
else
INSTALL_DIR="$HOME/.local/bin"
- APP_PATH="$INSTALL_DIR/$BIN_NAME"
+ sync_app_path
mkdir -p "$INSTALL_DIR"
install -m 755 "$TMP_DIR/$BIN_NAME" "$APP_PATH"
fi
diff --git a/src/tui/app/mod.rs b/src/tui/app/mod.rs
index 767d131..132a03b 100644
--- a/src/tui/app/mod.rs
+++ b/src/tui/app/mod.rs
@@ -97,8 +97,17 @@ impl App {
let _ = std::fs::create_dir_all(&app_dir);
let path = app_dir.join("tv_config.json");
if let Ok(json) = serde_json::to_string(&self.state.tv_playlists) {
- if let Err(error) = std::fs::write(&path, json) {
+ let temporary = path.with_extension(format!("{}.tmp", std::process::id()));
+ if let Err(error) = std::fs::write(&temporary, json) {
log::warn!("failed to save tv playlists: {error}");
+ return;
+ }
+ if std::fs::rename(&temporary, &path).is_err() {
+ let _ = std::fs::remove_file(&path);
+ if let Err(error) = std::fs::rename(&temporary, &path) {
+ let _ = std::fs::remove_file(&temporary);
+ log::warn!("failed to commit tv playlists: {error}");
+ }
}
}
}