Skip to content

Commit

Permalink
fix(tauri): docs.rs build error (#3974)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Apr 26, 2022
1 parent feac1d1 commit dd94917
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 45 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-tauri-docsrs.md
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Fixes `docs.rs` documentation build.
5 changes: 4 additions & 1 deletion core/tauri/Cargo.toml
Expand Up @@ -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" ]
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/api/error.rs
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions core/tauri/src/api/file.rs
Expand Up @@ -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;

Expand All @@ -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::*;

Expand Down
89 changes: 48 additions & 41 deletions core/tauri/src/api/file/extract.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
}
}
}
Expand All @@ -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))?;
}
}
}
}
Expand Down

0 comments on commit dd94917

Please sign in to comment.