Skip to content

Commit

Permalink
fix(utils): fix resources map becomes directory (#10293)
Browse files Browse the repository at this point in the history
* fix(utils): fix resources map becomes directory

closes #10187

Fixes the behavior of mapped resources generating extra directory, for example:
`"../resources/user.json": "resources/user.json"` generates this resource `resources/user.json/user.json`
where it should generate `resources/user.json`

This PR includes a refactor of the Iterator implementation which splits it into more scoped functions and relis on recursing instead of a loop which makes the code a lot more readable and easier to maintain.

* clippy

* cover more cases

* clippy

* fix glob into directory, not resolving target correctly

* return error when resource origin path doesn't exist

* fix resources example build

* Update .changes/resources-map-becoming-dirs.md

---------

Co-authored-by: Lucas Nogueira <[email protected]>
  • Loading branch information
amrbashir and lucasfernog authored Aug 17, 2024
1 parent 8deb196 commit 9e89193
Show file tree
Hide file tree
Showing 6 changed files with 505 additions and 130 deletions.
5 changes: 5 additions & 0 deletions .changes/resources-map-becoming-dirs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-utils": "patch:bug"
---

Fix `ResourcePaths` iterator returning an unexpected result for mapped resources, for example `"../resources/user.json": "resources/user.json"` generates this resource `resources/user.json/user.json` where it should generate just `resources/user.json`.
58 changes: 58 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions core/tauri-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ serde-untagged = "0.1"
[target."cfg(target_os = \"macos\")".dependencies]
swift-rs = { version = "1.0.6", optional = true, features = [ "build" ] }

[dev-dependencies]
getrandom = { version = "0.2", features = [ "std" ] }
serial_test = "3.1"

[features]
build = [
"proc-macro2",
Expand Down
4 changes: 4 additions & 0 deletions core/tauri-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ pub enum Error {
#[cfg(feature = "resources")]
#[error("could not walk directory `{0}`, try changing `allow_walk` to true on the `ResourcePaths` constructor.")]
NotAllowedToWalkDir(std::path::PathBuf),
/// Resourece path doesn't exist
#[cfg(feature = "resources")]
#[error("resource path `{0}` doesn't exist")]
ResourcePathNotFound(std::path::PathBuf),
}

/// Reconstructs a path from its components using the platform separator then converts it to String and removes UNC prefixes on Windows if it exists.
Expand Down
Loading

0 comments on commit 9e89193

Please sign in to comment.