Skip to content

Commit

Permalink
fix glob into directory, not resolving target correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Jul 18, 2024
1 parent c9a7bc1 commit 1f1ca94
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions core/tauri-utils/src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ impl<'a> ResourcePathsIter<'a> {

fn resource_from_path(&mut self, path: &Path) -> Resource {
Resource {
path: path.to_path_buf(),
target: self
.current_dest
.as_ref()
Expand All @@ -178,7 +179,7 @@ impl<'a> ResourcePathsIter<'a> {
let current_pattern = self.current_pattern.as_ref().unwrap();
current_dest.join(path.strip_prefix(current_pattern).unwrap_or(path))
} else if current_dest.components().count() == 0 {
// else if current_dest is empty while processing a file pattern or glob
// if current_dest is empty while processing a file pattern or glob
// we preserve the file name as it is
PathBuf::from(path.file_name().unwrap())
} else if self.glob_iter.is_some() {
Expand All @@ -191,7 +192,6 @@ impl<'a> ResourcePathsIter<'a> {
}
})
.unwrap_or_else(|| resource_relpath(path)),
path: path.to_path_buf(),
}
}

Expand All @@ -202,13 +202,17 @@ impl<'a> ResourcePathsIter<'a> {

let is_dir = path.is_dir();

if is_dir && !self.allow_walk {
return Some(Err(crate::Error::NotAllowedToWalkDir(path.to_path_buf())));
}

if is_dir {
if self.glob_iter.is_some() {
return self.next();
}

if !self.allow_walk {
return Some(Err(crate::Error::NotAllowedToWalkDir(path.to_path_buf())));
}

if self.walk_iter.is_none() {
self.walk_iter = Some(WalkDir::new(path).into_iter());
self.walk_iter = Some(WalkDir::new(&path).into_iter());
}

match self.next_walk_iter() {
Expand Down Expand Up @@ -341,6 +345,14 @@ mod tests {
Path::new("src/assets/lang/ar.json"),
Path::new("src/sounds/lang/es.wav"),
Path::new("src/sounds/lang/fr.wav"),
Path::new("src/textures/ground/earth.tex"),
Path::new("src/textures/ground/sand.tex"),
Path::new("src/textures/water.tex"),
Path::new("src/textures/fire.tex"),
Path::new("src/tiles/sky/grey.tile"),
Path::new("src/tiles/sky/yellow.tile"),
Path::new("src/tiles/grass.tile"),
Path::new("src/tiles/stones.tile"),
Path::new("src/index.html"),
Path::new("src/style.css"),
Path::new("src/script.js"),
Expand Down Expand Up @@ -454,6 +466,8 @@ mod tests {
("../src/assets".into(), "".into()),
("../src/index.html".into(), "frontend/index.html".into()),
("../src/sounds".into(), "voices".into()),
("../src/textures/*".into(), "textures".into()),
("../src/tiles/**/*".into(), "tiles".into()),
("*.toml".into(), "".into()),
("*.conf.json".into(), "json".into()),
]),
Expand All @@ -473,6 +487,12 @@ mod tests {
("../src/index.html", "frontend/index.html"),
("../src/sounds/lang/es.wav", "voices/lang/es.wav"),
("../src/sounds/lang/fr.wav", "voices/lang/fr.wav"),
("../src/textures/water.tex", "textures/water.tex"),
("../src/textures/fire.tex", "textures/fire.tex"),
("../src/tiles/grass.tile", "tiles/grass.tile"),
("../src/tiles/stones.tile", "tiles/stones.tile"),
("../src/tiles/sky/grey.tile", "tiles/grey.tile"),
("../src/tiles/sky/yellow.tile", "tiles/yellow.tile"),
("Cargo.toml", "Cargo.toml"),
("Tauri.toml", "Tauri.toml"),
("tauri.conf.json", "json/tauri.conf.json"),
Expand Down

0 comments on commit 1f1ca94

Please sign in to comment.