Skip to content

Commit

Permalink
does this fix macOS ?
Browse files Browse the repository at this point in the history
  • Loading branch information
amr-crabnebula committed Nov 30, 2023
1 parent 4680a8a commit d9ec4ec
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
16 changes: 16 additions & 0 deletions crates/packager/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,22 @@ fn make_icns_image(img: image::DynamicImage) -> std::io::Result<icns::Image> {
}

/// Writes a tar file to the given writer containing the given directory.
///
/// The generated tar contains the `src_dir` as a whole and not just its files,
/// so if we are creating a tar for:
/// ```text
/// dir/
/// |_ file1
/// |_ file2
/// |_ file3
/// ```
/// the generated tar will contain the following entries:
/// ```text
/// - dir
/// - dir/file1
/// - dir/file2
/// - dir/file3
/// ```
pub fn create_tar_from_dir<P: AsRef<Path>, W: Write>(src_dir: P, dest_file: W) -> crate::Result<W> {
let src_dir = src_dir.as_ref();
let filename = src_dir
Expand Down
41 changes: 17 additions & 24 deletions crates/updater/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,6 @@ impl Update {
use flate2::read::GzDecoder;

let cursor = Cursor::new(bytes);
let mut extracted_files: Vec<PathBuf> = Vec::new();

// the first file in the tar.gz will always be
// <app_name>/Contents
Expand All @@ -767,33 +766,27 @@ impl Update {
let decoder = GzDecoder::new(cursor);
let mut archive = tar::Archive::new(decoder);

std::fs::create_dir(&self.extract_path)?;

for entry in archive.entries()? {
let mut entry = entry?;

let extraction_path = &self.extract_path.join(entry.path()?);

// if something went wrong during the extraction, we should restore previous app
if let Err(err) = entry.unpack(extraction_path) {
for file in extracted_files.iter().rev() {
// delete all the files we extracted
if file.is_dir() {
std::fs::remove_dir(file)?;
} else {
std::fs::remove_file(file)?;
}
}
std::fs::rename(tmp_dir.path(), &self.extract_path)?;
return Err(err.into());
fn extract_archive(archive: tar::Archive, extract_path: &Path) -> Result<()> {
std::fs::create_dir(extract_path)?;
for entry in archive.entries()? {
let mut entry = entry?;
let entry_path: PathBuf = entry.path()?.components().skip(1).collect();
entry.unpack(extract_path.join(entry_path))?;
}

extracted_files.push(extraction_path.to_path_buf());
let _ = std::process::Command::new("touch")
.arg(extract_path)
.status();

Ok(())
}

let _ = std::process::Command::new("touch")
.arg(&self.extract_path)
.status();
// if something went wrong during the extraction, we should restore previous app
if let Err(e) = extract_archive(archive, self.extract_path) {
std::fs::remove_dir(extract_path)?;
std::fs::rename(tmp_dir.path(), &self.extract_path)?;
return Err(e);
}

Ok(())
}
Expand Down

0 comments on commit d9ec4ec

Please sign in to comment.