Enum tauri::api::file::Entry

source ·
#[non_exhaustive]
pub enum Entry<'a, R: Read> {
    Tar(Box<Entry<'a, R>>),
    Zip(ZipEntry),
}
Expand description

A read-only view into an entry of an archive.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Tar(Box<Entry<'a, R>>)

An entry of a tar archive.

§

Zip(ZipEntry)

An entry of a zip archive.

Implementations§

The entry path.

Examples found in repository?
src/updater/core.rs (line 680)
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
fn copy_files_and_run<R: Read + Seek>(archive_buffer: R, extract_path: &Path) -> Result {
  use std::os::unix::fs::{MetadataExt, PermissionsExt};

  let extract_path_metadata = extract_path.metadata()?;

  let tmp_dir_locations = vec![
    Box::new(|| Some(env::temp_dir())) as Box<dyn FnOnce() -> Option<PathBuf>>,
    Box::new(dirs_next::cache_dir),
    Box::new(|| Some(extract_path.parent().unwrap().to_path_buf())),
  ];

  for tmp_dir_location in tmp_dir_locations {
    if let Some(tmp_dir_location) = tmp_dir_location() {
      let tmp_dir = tempfile::Builder::new()
        .prefix("tauri_current_app")
        .tempdir_in(tmp_dir_location)?;
      let tmp_dir_metadata = tmp_dir.path().metadata()?;

      if extract_path_metadata.dev() == tmp_dir_metadata.dev() {
        let mut perms = tmp_dir_metadata.permissions();
        perms.set_mode(0o700);
        std::fs::set_permissions(tmp_dir.path(), perms)?;

        let tmp_app_image = &tmp_dir.path().join("current_app.AppImage");

        // create a backup of our current app image
        Move::from_source(extract_path).to_dest(tmp_app_image)?;

        // extract the buffer to the tmp_dir
        // we extract our signed archive into our final directory without any temp file
        let mut extractor =
          Extract::from_cursor(archive_buffer, ArchiveFormat::Tar(Some(Compression::Gz)));

        return extractor
          .with_files(|entry| {
            let path = entry.path()?;
            if path.extension() == Some(OsStr::new("AppImage")) {
              // if something went wrong during the extraction, we should restore previous app
              if let Err(err) = entry.extract(extract_path) {
                Move::from_source(tmp_app_image).to_dest(extract_path)?;
                return Err(crate::api::Error::Extract(err.to_string()));
              }
              // early finish we have everything we need here
              return Ok(true);
            }
            Ok(false)
          })
          .map_err(Into::into);
      }
    }
  }

  Err(Error::TempDirNotOnSameMountPoint)
}

Extract this entry into into_path. If it’s a directory, the target will be created, if it’s a file, it’ll be extracted at this location. Note: You need to include the complete path, with file name and extension.

Examples found in repository?
src/updater/core.rs (line 683)
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
fn copy_files_and_run<R: Read + Seek>(archive_buffer: R, extract_path: &Path) -> Result {
  use std::os::unix::fs::{MetadataExt, PermissionsExt};

  let extract_path_metadata = extract_path.metadata()?;

  let tmp_dir_locations = vec![
    Box::new(|| Some(env::temp_dir())) as Box<dyn FnOnce() -> Option<PathBuf>>,
    Box::new(dirs_next::cache_dir),
    Box::new(|| Some(extract_path.parent().unwrap().to_path_buf())),
  ];

  for tmp_dir_location in tmp_dir_locations {
    if let Some(tmp_dir_location) = tmp_dir_location() {
      let tmp_dir = tempfile::Builder::new()
        .prefix("tauri_current_app")
        .tempdir_in(tmp_dir_location)?;
      let tmp_dir_metadata = tmp_dir.path().metadata()?;

      if extract_path_metadata.dev() == tmp_dir_metadata.dev() {
        let mut perms = tmp_dir_metadata.permissions();
        perms.set_mode(0o700);
        std::fs::set_permissions(tmp_dir.path(), perms)?;

        let tmp_app_image = &tmp_dir.path().join("current_app.AppImage");

        // create a backup of our current app image
        Move::from_source(extract_path).to_dest(tmp_app_image)?;

        // extract the buffer to the tmp_dir
        // we extract our signed archive into our final directory without any temp file
        let mut extractor =
          Extract::from_cursor(archive_buffer, ArchiveFormat::Tar(Some(Compression::Gz)));

        return extractor
          .with_files(|entry| {
            let path = entry.path()?;
            if path.extension() == Some(OsStr::new("AppImage")) {
              // if something went wrong during the extraction, we should restore previous app
              if let Err(err) = entry.extract(extract_path) {
                Move::from_source(tmp_app_image).to_dest(extract_path)?;
                return Err(crate::api::Error::Extract(err.to_string()));
              }
              // early finish we have everything we need here
              return Ok(true);
            }
            Ok(false)
          })
          .map_err(Into::into);
      }
    }
  }

  Err(Error::TempDirNotOnSameMountPoint)
}

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more