Skip to content

Commit

Permalink
restore permissions on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog-crabnebula committed Nov 17, 2023
1 parent a663ae0 commit 690c35c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/updater/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,11 +686,16 @@ impl Update {
.tempfile_in(tmp_dir)?
.keep()?;

// get metadata to restore later
let metadata = self.extract_path.metadata()?;

// create a backup of our current app image
std::fs::rename(&self.extract_path, &tmp_app_image)?;

// if something went wrong during the extraction, we should restore previous app
if let Err(err) = std::fs::write(&self.extract_path, bytes) {
if let Err(err) = std::fs::write(&self.extract_path, bytes).and_then(|_| {
std::fs::set_permissions(&self.extract_path, metadata.permissions())
}) {
std::fs::rename(tmp_app_image, &self.extract_path)?;
return Err(err.into());
}
Expand Down

0 comments on commit 690c35c

Please sign in to comment.