Ver código fonte

fix(tauri): docs.rs build error (#3974)

Lucas Fernandes Nogueira 3 anos atrás
pai
commit
dd94917b61

+ 5 - 0
.changes/fix-tauri-docsrs.md

@@ -0,0 +1,5 @@
+---
+"tauri": patch
+---
+
+Fixes `docs.rs` documentation build.

+ 4 - 1
core/tauri/Cargo.toml

@@ -26,9 +26,12 @@ features = [
   "api-all",
   "cli",
   "__updater-docs",
+  "__fs-extract-api-docs",
   "system-tray",
   "devtools",
   "http-multipart",
+  "gtk-tray",
+  "icon-png",
   "dox"
 ]
 rustdoc-args = [ "--cfg", "doc_cfg" ]
@@ -64,7 +67,6 @@ tar = "0.4.36"
 tempfile = "3"
 zip = { version = "0.6", default-features = false, optional = true }
 ignore = "0.4"
-either = "1.6"
 flate2 = "1.0"
 http = "0.2"
 bincode = "1.3"
@@ -140,6 +142,7 @@ http-api = [ "attohttpc" ]
 http-multipart = [ "attohttpc/multipart-form", "reqwest/multipart" ]
 shell-open-api = [ "open", "regex", "tauri-macros/shell-scope" ]
 fs-extract-api = [ "zip" ]
+__fs-extract-api-docs = [ ]
 reqwest-client = [ "reqwest", "bytes" ]
 process-command-api = [ "shared_child", "os_pipe" ]
 global-shortcut = [

+ 1 - 1
core/tauri/src/api/error.rs

@@ -67,7 +67,7 @@ pub enum Error {
   #[error(transparent)]
   Zip(#[from] zip::result::ZipError),
   /// Extract error.
-  #[cfg(feature = "fs-extract-api")]
+  #[cfg(any(feature = "fs-extract-api", feature = "__fs-extract-api-docs"))]
   #[error("Failed to extract: {0}")]
   Extract(String),
   /// Notification error.

+ 2 - 2
core/tauri/src/api/file.rs

@@ -4,7 +4,7 @@
 
 //! Types and functions related to file operations.
 
-#[cfg(feature = "fs-extract-api")]
+#[cfg(any(feature = "fs-extract-api", feature = "__fs-extract-api-docs"))]
 mod extract;
 mod file_move;
 
@@ -13,7 +13,7 @@ use std::{
   path::{Display, Path},
 };
 
-#[cfg(feature = "fs-extract-api")]
+#[cfg(any(feature = "fs-extract-api", feature = "__fs-extract-api-docs"))]
 pub use extract::*;
 pub use file_move::*;
 

+ 48 - 41
core/tauri/src/api/file/extract.rs

@@ -28,6 +28,7 @@ impl<R: Read + Seek> Read for ArchiveReader<R> {
 }
 
 impl<R: Read + Seek> ArchiveReader<R> {
+  #[allow(dead_code)]
   fn get_mut(&mut self) -> &mut R {
     match self {
       Self::Plain(r) => r,
@@ -192,24 +193,27 @@ impl<'a, R: Read + Seek> Extract<'a, R> {
       }
 
       ArchiveFormat::Zip => {
-        let mut archive = zip::ZipArchive::new(self.reader.get_mut())?;
-        let file_names = archive
-          .file_names()
-          .map(|f| f.to_string())
-          .collect::<Vec<String>>();
-        for path in file_names {
-          let mut zip_file = archive.by_name(&path)?;
-          let is_dir = zip_file.is_dir();
-          let mut file_contents = Vec::new();
-          zip_file.read_to_end(&mut file_contents)?;
-          let stop = f(Entry::Zip(ZipEntry {
-            path: path.into(),
-            is_dir,
-            file_contents,
-          }))
-          .map_err(Into::into)?;
-          if stop {
-            break;
+        #[cfg(feature = "fs-extract-api")]
+        {
+          let mut archive = zip::ZipArchive::new(self.reader.get_mut())?;
+          let file_names = archive
+            .file_names()
+            .map(|f| f.to_string())
+            .collect::<Vec<String>>();
+          for path in file_names {
+            let mut zip_file = archive.by_name(&path)?;
+            let is_dir = zip_file.is_dir();
+            let mut file_contents = Vec::new();
+            zip_file.read_to_end(&mut file_contents)?;
+            let stop = f(Entry::Zip(ZipEntry {
+              path: path.into(),
+              is_dir,
+              file_contents,
+            }))
+            .map_err(Into::into)?;
+            if stop {
+              break;
+            }
           }
         }
       }
@@ -229,30 +233,33 @@ impl<'a, R: Read + Seek> Extract<'a, R> {
       }
 
       ArchiveFormat::Zip => {
-        let mut archive = zip::ZipArchive::new(self.reader.get_mut())?;
-        for i in 0..archive.len() {
-          let mut file = archive.by_index(i)?;
-          // Decode the file name from raw bytes instead of using file.name() directly.
-          // file.name() uses String::from_utf8_lossy() which may return messy characters
-          // such as: 爱交易.app/, that does not work as expected.
-          // Here we require the file name must be a valid UTF-8.
-          let file_name = String::from_utf8(file.name_raw().to_vec())?;
-          let out_path = into_dir.join(&file_name);
-          if file.is_dir() {
-            fs::create_dir_all(&out_path)?;
-          } else {
-            if let Some(out_path_parent) = out_path.parent() {
-              fs::create_dir_all(&out_path_parent)?;
+        #[cfg(feature = "fs-extract-api")]
+        {
+          let mut archive = zip::ZipArchive::new(self.reader.get_mut())?;
+          for i in 0..archive.len() {
+            let mut file = archive.by_index(i)?;
+            // Decode the file name from raw bytes instead of using file.name() directly.
+            // file.name() uses String::from_utf8_lossy() which may return messy characters
+            // such as: 爱交易.app/, that does not work as expected.
+            // Here we require the file name must be a valid UTF-8.
+            let file_name = String::from_utf8(file.name_raw().to_vec())?;
+            let out_path = into_dir.join(&file_name);
+            if file.is_dir() {
+              fs::create_dir_all(&out_path)?;
+            } else {
+              if let Some(out_path_parent) = out_path.parent() {
+                fs::create_dir_all(&out_path_parent)?;
+              }
+              let mut out_file = fs::File::create(&out_path)?;
+              io::copy(&mut file, &mut out_file)?;
             }
-            let mut out_file = fs::File::create(&out_path)?;
-            io::copy(&mut file, &mut out_file)?;
-          }
-          // Get and Set permissions
-          #[cfg(unix)]
-          {
-            use std::os::unix::fs::PermissionsExt;
-            if let Some(mode) = file.unix_mode() {
-              fs::set_permissions(&out_path, fs::Permissions::from_mode(mode))?;
+            // Get and Set permissions
+            #[cfg(unix)]
+            {
+              use std::os::unix::fs::PermissionsExt;
+              if let Some(mode) = file.unix_mode() {
+                fs::set_permissions(&out_path, fs::Permissions::from_mode(mode))?;
+              }
             }
           }
         }