fix: resource path handles ./ path differently - #14662
Conversation
Package Changes Through 47ff324There are 4 changes which include tauri-cli with patch, @tauri-apps/cli with patch, tauri-utils with patch, tauri-bundler with patch Planned Package VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
| let path = normalize(Path::new(pattern)); | ||
| if path.is_dir() { | ||
| if !self.allow_walk { | ||
| return Some(Err(crate::Error::NotAllowedToWalkDir(path))); | ||
| } | ||
| self.current_iter = Some(ResourcePathsInnerIter::Walk { | ||
| iter: WalkDir::new(&path).into_iter(), | ||
| current_pattern: if matches!(self.pattern_iter, PatternIter::Map(_)) { | ||
| Some(path) | ||
| } else { | ||
| None | ||
| }, | ||
| }); | ||
| } else { | ||
| return Some(self.resource_from_path(path)); | ||
| } |
There was a problem hiding this comment.
This replaced next_current_path
| current_iter: Option<ResourcePathsInnerIter>, | ||
| } | ||
|
|
||
| impl ResourcePathsIter<'_> { | ||
| fn next_glob_iter(&mut self) -> Option<crate::Result<Resource>> { | ||
| let entry = self.glob_iter.as_mut().unwrap().next()?; | ||
| #[derive(Debug)] | ||
| enum ResourcePathsInnerIter { | ||
| Walk { | ||
| iter: walkdir::IntoIter, | ||
| current_pattern: Option<PathBuf>, | ||
| }, | ||
| Glob { | ||
| iter: glob::Paths, | ||
| }, | ||
| } | ||
|
|
||
| let entry = match entry { | ||
| Ok(entry) => entry, | ||
| Err(err) => return Some(Err(err.into())), | ||
| }; | ||
| impl Iterator for ResourcePathsInnerIter { | ||
| type Item = crate::Result<PathBuf>; | ||
|
|
||
| self.next_current_path(normalize(&entry)) | ||
| fn next(&mut self) -> Option<crate::Result<PathBuf>> { | ||
| match self { | ||
| ResourcePathsInnerIter::Walk { iter, .. } => Some( | ||
| iter | ||
| .next()? | ||
| .map(|entry| entry.into_path()) | ||
| .map_err(Into::into), | ||
| ), | ||
| ResourcePathsInnerIter::Glob { iter } => Some(iter.next()?.map_err(Into::into)), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn next_walk_iter(&mut self) -> Option<crate::Result<Resource>> { | ||
| let entry = self.walk_iter.as_mut().unwrap().next()?; | ||
|
|
||
| let entry = match entry { | ||
| Ok(entry) => entry, | ||
| Err(err) => return Some(Err(err.into())), | ||
| }; | ||
|
|
||
| self.next_current_path(normalize(entry.path())) | ||
| impl ResourcePathsIter<'_> { | ||
| fn next_current_iter(&mut self) -> Option<crate::Result<Resource>> { | ||
| let current_iter = self.current_iter.as_mut().unwrap(); | ||
| let entry = current_iter.next()?; | ||
|
|
||
| Some(match entry { | ||
| Ok(entry) => { | ||
| // Skip directories | ||
| if entry.is_dir() { | ||
| self.next_current_iter()? | ||
| } else { | ||
| self.resource_from_path(normalize(&entry)) | ||
| } | ||
| } | ||
| Err(error) => Err(error), | ||
| }) | ||
| } |
There was a problem hiding this comment.
Grouped walk iter and glob iter into a enum since they're mutually exclusive
| ( | ||
| "../src/textures/ground/earth.tex", | ||
| "_up_/src/textures/earth.tex", | ||
| "_up_/src/textures/ground/earth.tex", |
There was a problem hiding this comment.
We didn't run those tests before and they were failing from the very beginning...
| // if processing a directory, preserve directory structure under current_dest | ||
| if self.walk_iter.is_some() { | ||
| dest.join(path.strip_prefix(pattern).unwrap_or(path)) | ||
| } else if dest.components().count() == 0 { |
There was a problem hiding this comment.
Is this possible? We have normalized this path and join for an empty PathBuf (PathBuf::from("")) should be the same as what's joined to anyways
|
Is it fine that CI wasn't green? Looks like the tests in |
|
No, missed it completely since we got too many false alarms on the cache fail 🤦♂️ |
* fix: resource path handles `./` path differently * Setup CI for tauri utils * Wrong job name * Fix tests * Always run tests and don't run doc tests * Add change file * Re-use `test-core` workflow * Format * Avoid path clone by calculating target first * Test tauri-utils first with step instead of matrix * Use `matrix.platform.command` * Document `current_dest` and `current_pattern` * More docs * Merge remote-tracking branch 'upstream/dev' into refactor-resource-path-iter * Test with doc tests * Revert "Test with doc tests" This reverts commit 388bee9. * Merge branch 'dev' into refactor-resource-path-iter * Merge branch 'dev' into refactor-resource-path-iter
* fix: resource path handles `./` path differently * Setup CI for tauri utils * Wrong job name * Fix tests * Always run tests and don't run doc tests * Add change file * Re-use `test-core` workflow * Format * Avoid path clone by calculating target first * Test tauri-utils first with step instead of matrix * Use `matrix.platform.command` * Document `current_dest` and `current_pattern` * More docs * Merge remote-tracking branch 'upstream/dev' into refactor-resource-path-iter * Test with doc tests * Revert "Test with doc tests" This reverts commit 388bee9. * Merge branch 'dev' into refactor-resource-path-iter * Merge branch 'dev' into refactor-resource-path-iter
* fix: resource path handles `./` path differently * Setup CI for tauri utils * Wrong job name * Fix tests * Always run tests and don't run doc tests * Add change file * Re-use `test-core` workflow * Format * Avoid path clone by calculating target first * Test tauri-utils first with step instead of matrix * Use `matrix.platform.command` * Document `current_dest` and `current_pattern` * More docs * Merge remote-tracking branch 'upstream/dev' into refactor-resource-path-iter * Test with doc tests * Revert "Test with doc tests" This reverts commit 388bee9. * Merge branch 'dev' into refactor-resource-path-iter * Merge branch 'dev' into refactor-resource-path-iter
Fix #14659
Also added CI for
tauri-utils