Conversation
NamedTempFile::into_file() consumes the handle and deletes the file from disk. dpkg then fails with "No such file or directory". Use keep() instead to persist the file, and clean it up manually after. Also fix compiler warning: cast function pointer via *const () first. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use into_parts() to get a TempPath (RAII auto-delete on drop) instead of keep(). The file is cleaned up on download errors, write errors, and install failures — not just the success path. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fix: Linux deb updater temp file deleted before dpkg install
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adjusts low-level platform integration in the Tauri desktop app by fixing a signal handler cast and improving temporary file lifecycle management during package updates.
Changes:
- Update
sigaction.sa_sigactionassignment to use an explicit pointer-to-integer cast. - Rework package update temp file handling to keep the path alive (RAII) and rely on auto-cleanup rather than manual deletion.
- Add inline documentation explaining the temp file lifetime/cleanup approach.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| apps/desktop/src-tauri/src/lib.rs | Updates signal handler casting for sigaction setup. |
| apps/desktop/src-tauri/src/commands.rs | Uses NamedTempFile::into_parts() and TempPath to ensure the update artifact is cleaned up via RAII instead of manual remove_file. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // keep() disables auto-delete and returns a TempPath (RAII: deletes on drop) | ||
| // plus the raw File handle for writing. TempPath stays alive until end of | ||
| // function, so dpkg/rpm can access the file, and cleanup happens on all paths. |
There was a problem hiding this comment.
These comments are inaccurate: this code uses into_parts(), not keep(). In tempfile, keep() typically disables auto-delete and returns a persisted path, while into_parts() returns a TempPath that deletes on drop. Please update the comment to describe into_parts()/TempPath behavior so future maintainers don’t misunderstand the cleanup semantics.
| // keep() disables auto-delete and returns a TempPath (RAII: deletes on drop) | |
| // plus the raw File handle for writing. TempPath stays alive until end of | |
| // function, so dpkg/rpm can access the file, and cleanup happens on all paths. | |
| // into_parts() splits the NamedTempFile into the raw File handle plus a | |
| // TempPath. Keeping TempPath alive preserves the path for dpkg/rpm to read, | |
| // and the temp file is still deleted automatically when TempPath is dropped. |
| .map_err(|e| format!("Failed to create temp file: {e}"))?; | ||
| let tmp_path = temp_file.path().to_path_buf(); | ||
| let mut file = tokio::fs::File::from_std(temp_file.into_file()); | ||
| let (std_file, tmp_path) = temp_file.into_parts(); |
There was a problem hiding this comment.
tmp_path is now a TempPath (RAII handle), not a plain PathBuf. Consider renaming to something like temp_path or temp_path_handle to reduce confusion and make the drop-based deletion behavior more obvious.
| let mut action: libc::sigaction = std::mem::zeroed(); | ||
| action.sa_flags = libc::SA_RESETHAND; | ||
| action.sa_sigaction = crash_handler as usize; | ||
| action.sa_sigaction = crash_handler as *const () as usize; |
There was a problem hiding this comment.
Casting a function to *const () and then to usize is a brittle way to populate sa_sigaction and obscures the intended ABI/type. Prefer assigning using the libc-provided handler type (e.g., libc::sighandler_t where available) or a clearly documented, platform-appropriate conversion, so this remains portable across targets where the field type/layout differs.
| action.sa_sigaction = crash_handler as *const () as usize; | |
| action.sa_sigaction = crash_handler as libc::sighandler_t; |
No description provided.