Skip to content

Commit 3fd8ba2

Browse files
fix: resources after empty directory not copied (#15388)
* fix: resources after empty directory not copied * typo * Add empty directory test
1 parent 47e1b75 commit 3fd8ba2

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
"tauri-utils": "patch:bug"
3+
---
4+
5+
Fix a regression in tauri-utils 2.8.3 that made an empty directory makes it skip all the following entries, e.g.
6+
7+
```json
8+
{
9+
"bundle": {
10+
"resources": [
11+
"empty-directory",
12+
"README.md"
13+
]
14+
}
15+
}
16+
```
17+
18+
if `empty-directory` is empty, the `README.md` will not be copied to the resource directory (skipped)

crates/tauri-utils/src/resources.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ impl ResourcePathsIter<'_> {
221221

222222
fn next_pattern(&mut self) -> Option<crate::Result<Resource>> {
223223
self.current_dest = None;
224+
self.current_iter = None;
224225

225226
let pattern = match &mut self.pattern_iter {
226227
PatternIter::Slice(iter) => iter.next()?,
@@ -237,10 +238,10 @@ impl ResourcePathsIter<'_> {
237238
Err(error) => return Some(Err(error.into())),
238239
};
239240
match self.next_current_iter() {
240-
Some(r) => return Some(r),
241+
Some(r) => Some(r),
241242
None => {
242243
self.current_iter = None;
243-
return Some(Err(crate::Error::GlobPathNotFound(pattern.clone())));
244+
Some(Err(crate::Error::GlobPathNotFound(pattern.clone())))
244245
}
245246
}
246247
} else {
@@ -257,12 +258,12 @@ impl ResourcePathsIter<'_> {
257258
None
258259
},
259260
});
261+
// If the directory is empty, skip and continue to the next pattern
262+
self.next_current_iter().or_else(|| self.next_pattern())
260263
} else {
261-
return Some(self.resource_from_path(path));
264+
Some(self.resource_from_path(path))
262265
}
263266
}
264-
265-
self.next_current_iter()
266267
}
267268
}
268269

@@ -358,6 +359,7 @@ mod tests {
358359
fs::create_dir_all(path.parent().unwrap()).unwrap();
359360
fs::write(path, "").unwrap();
360361
}
362+
fs::create_dir_all("empty-directory").unwrap();
361363
}
362364

363365
fn resources_map(literal: &[(&str, &str)]) -> HashMap<String, String> {
@@ -377,6 +379,8 @@ mod tests {
377379

378380
let resources = ResourcePaths::new(
379381
&[
382+
// `empty-directory` should not affect anything
383+
"../empty-directory".into(),
380384
"../src/script.js".into(),
381385
"../src/assets".into(),
382386
"../src/index.html".into(),

0 commit comments

Comments
 (0)