Skip to content

Commit dd94917

Browse files
authored
fix(tauri): docs.rs build error (#3974)
1 parent feac1d1 commit dd94917

File tree

5 files changed

+60
-45
lines changed

5 files changed

+60
-45
lines changed

.changes/fix-tauri-docsrs.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Fixes `docs.rs` documentation build.

core/tauri/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ features = [
2626
"api-all",
2727
"cli",
2828
"__updater-docs",
29+
"__fs-extract-api-docs",
2930
"system-tray",
3031
"devtools",
3132
"http-multipart",
33+
"gtk-tray",
34+
"icon-png",
3235
"dox"
3336
]
3437
rustdoc-args = [ "--cfg", "doc_cfg" ]
@@ -64,7 +67,6 @@ tar = "0.4.36"
6467
tempfile = "3"
6568
zip = { version = "0.6", default-features = false, optional = true }
6669
ignore = "0.4"
67-
either = "1.6"
6870
flate2 = "1.0"
6971
http = "0.2"
7072
bincode = "1.3"
@@ -140,6 +142,7 @@ http-api = [ "attohttpc" ]
140142
http-multipart = [ "attohttpc/multipart-form", "reqwest/multipart" ]
141143
shell-open-api = [ "open", "regex", "tauri-macros/shell-scope" ]
142144
fs-extract-api = [ "zip" ]
145+
__fs-extract-api-docs = [ ]
143146
reqwest-client = [ "reqwest", "bytes" ]
144147
process-command-api = [ "shared_child", "os_pipe" ]
145148
global-shortcut = [

core/tauri/src/api/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub enum Error {
6767
#[error(transparent)]
6868
Zip(#[from] zip::result::ZipError),
6969
/// Extract error.
70-
#[cfg(feature = "fs-extract-api")]
70+
#[cfg(any(feature = "fs-extract-api", feature = "__fs-extract-api-docs"))]
7171
#[error("Failed to extract: {0}")]
7272
Extract(String),
7373
/// Notification error.

core/tauri/src/api/file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
//! Types and functions related to file operations.
66
7-
#[cfg(feature = "fs-extract-api")]
7+
#[cfg(any(feature = "fs-extract-api", feature = "__fs-extract-api-docs"))]
88
mod extract;
99
mod file_move;
1010

@@ -13,7 +13,7 @@ use std::{
1313
path::{Display, Path},
1414
};
1515

16-
#[cfg(feature = "fs-extract-api")]
16+
#[cfg(any(feature = "fs-extract-api", feature = "__fs-extract-api-docs"))]
1717
pub use extract::*;
1818
pub use file_move::*;
1919

core/tauri/src/api/file/extract.rs

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ impl<R: Read + Seek> Read for ArchiveReader<R> {
2828
}
2929

3030
impl<R: Read + Seek> ArchiveReader<R> {
31+
#[allow(dead_code)]
3132
fn get_mut(&mut self) -> &mut R {
3233
match self {
3334
Self::Plain(r) => r,
@@ -192,24 +193,27 @@ impl<'a, R: Read + Seek> Extract<'a, R> {
192193
}
193194

194195
ArchiveFormat::Zip => {
195-
let mut archive = zip::ZipArchive::new(self.reader.get_mut())?;
196-
let file_names = archive
197-
.file_names()
198-
.map(|f| f.to_string())
199-
.collect::<Vec<String>>();
200-
for path in file_names {
201-
let mut zip_file = archive.by_name(&path)?;
202-
let is_dir = zip_file.is_dir();
203-
let mut file_contents = Vec::new();
204-
zip_file.read_to_end(&mut file_contents)?;
205-
let stop = f(Entry::Zip(ZipEntry {
206-
path: path.into(),
207-
is_dir,
208-
file_contents,
209-
}))
210-
.map_err(Into::into)?;
211-
if stop {
212-
break;
196+
#[cfg(feature = "fs-extract-api")]
197+
{
198+
let mut archive = zip::ZipArchive::new(self.reader.get_mut())?;
199+
let file_names = archive
200+
.file_names()
201+
.map(|f| f.to_string())
202+
.collect::<Vec<String>>();
203+
for path in file_names {
204+
let mut zip_file = archive.by_name(&path)?;
205+
let is_dir = zip_file.is_dir();
206+
let mut file_contents = Vec::new();
207+
zip_file.read_to_end(&mut file_contents)?;
208+
let stop = f(Entry::Zip(ZipEntry {
209+
path: path.into(),
210+
is_dir,
211+
file_contents,
212+
}))
213+
.map_err(Into::into)?;
214+
if stop {
215+
break;
216+
}
213217
}
214218
}
215219
}
@@ -229,30 +233,33 @@ impl<'a, R: Read + Seek> Extract<'a, R> {
229233
}
230234

231235
ArchiveFormat::Zip => {
232-
let mut archive = zip::ZipArchive::new(self.reader.get_mut())?;
233-
for i in 0..archive.len() {
234-
let mut file = archive.by_index(i)?;
235-
// Decode the file name from raw bytes instead of using file.name() directly.
236-
// file.name() uses String::from_utf8_lossy() which may return messy characters
237-
// such as: 爱交易.app/, that does not work as expected.
238-
// Here we require the file name must be a valid UTF-8.
239-
let file_name = String::from_utf8(file.name_raw().to_vec())?;
240-
let out_path = into_dir.join(&file_name);
241-
if file.is_dir() {
242-
fs::create_dir_all(&out_path)?;
243-
} else {
244-
if let Some(out_path_parent) = out_path.parent() {
245-
fs::create_dir_all(&out_path_parent)?;
236+
#[cfg(feature = "fs-extract-api")]
237+
{
238+
let mut archive = zip::ZipArchive::new(self.reader.get_mut())?;
239+
for i in 0..archive.len() {
240+
let mut file = archive.by_index(i)?;
241+
// Decode the file name from raw bytes instead of using file.name() directly.
242+
// file.name() uses String::from_utf8_lossy() which may return messy characters
243+
// such as: 爱交易.app/, that does not work as expected.
244+
// Here we require the file name must be a valid UTF-8.
245+
let file_name = String::from_utf8(file.name_raw().to_vec())?;
246+
let out_path = into_dir.join(&file_name);
247+
if file.is_dir() {
248+
fs::create_dir_all(&out_path)?;
249+
} else {
250+
if let Some(out_path_parent) = out_path.parent() {
251+
fs::create_dir_all(&out_path_parent)?;
252+
}
253+
let mut out_file = fs::File::create(&out_path)?;
254+
io::copy(&mut file, &mut out_file)?;
246255
}
247-
let mut out_file = fs::File::create(&out_path)?;
248-
io::copy(&mut file, &mut out_file)?;
249-
}
250-
// Get and Set permissions
251-
#[cfg(unix)]
252-
{
253-
use std::os::unix::fs::PermissionsExt;
254-
if let Some(mode) = file.unix_mode() {
255-
fs::set_permissions(&out_path, fs::Permissions::from_mode(mode))?;
256+
// Get and Set permissions
257+
#[cfg(unix)]
258+
{
259+
use std::os::unix::fs::PermissionsExt;
260+
if let Some(mode) = file.unix_mode() {
261+
fs::set_permissions(&out_path, fs::Permissions::from_mode(mode))?;
262+
}
256263
}
257264
}
258265
}

0 commit comments

Comments
 (0)