mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-09-10 23:45:46 +03:00
return error when resource origin path doesn't exist
This commit is contained in:
parent
1f1ca94bea
commit
b0b0205280
@ -371,6 +371,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.
|
||||
|
@ -167,8 +167,12 @@ impl<'a> ResourcePathsIter<'a> {
|
||||
self.next_current_path()
|
||||
}
|
||||
|
||||
fn resource_from_path(&mut self, path: &Path) -> Resource {
|
||||
Resource {
|
||||
fn resource_from_path(&mut self, path: &Path) -> crate::Result<Resource> {
|
||||
if !path.exists() {
|
||||
return Err(crate::Error::ResourcePathNotFound(path.to_path_buf()));
|
||||
}
|
||||
|
||||
Ok(Resource {
|
||||
path: path.to_path_buf(),
|
||||
target: self
|
||||
.current_dest
|
||||
@ -192,7 +196,7 @@ impl<'a> ResourcePathsIter<'a> {
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|| resource_relpath(path)),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn next_current_path(&mut self) -> Option<crate::Result<Resource>> {
|
||||
@ -223,7 +227,7 @@ impl<'a> ResourcePathsIter<'a> {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Some(Ok(self.resource_from_path(&path)))
|
||||
Some(self.resource_from_path(&path))
|
||||
}
|
||||
}
|
||||
|
||||
@ -470,6 +474,8 @@ mod tests {
|
||||
("../src/tiles/**/*".into(), "tiles".into()),
|
||||
("*.toml".into(), "".into()),
|
||||
("*.conf.json".into(), "json".into()),
|
||||
("../non-existent-file".into(), "asd".into()), // invalid case
|
||||
("../non/*".into(), "asd".into()), // invalid case
|
||||
]),
|
||||
true,
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user