mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-09-17 11:17:28 +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")]
|
#[cfg(feature = "resources")]
|
||||||
#[error("could not walk directory `{0}`, try changing `allow_walk` to true on the `ResourcePaths` constructor.")]
|
#[error("could not walk directory `{0}`, try changing `allow_walk` to true on the `ResourcePaths` constructor.")]
|
||||||
NotAllowedToWalkDir(std::path::PathBuf),
|
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.
|
/// 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()
|
self.next_current_path()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resource_from_path(&mut self, path: &Path) -> Resource {
|
fn resource_from_path(&mut self, path: &Path) -> crate::Result<Resource> {
|
||||||
Resource {
|
if !path.exists() {
|
||||||
|
return Err(crate::Error::ResourcePathNotFound(path.to_path_buf()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Resource {
|
||||||
path: path.to_path_buf(),
|
path: path.to_path_buf(),
|
||||||
target: self
|
target: self
|
||||||
.current_dest
|
.current_dest
|
||||||
@ -192,7 +196,7 @@ impl<'a> ResourcePathsIter<'a> {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| resource_relpath(path)),
|
.unwrap_or_else(|| resource_relpath(path)),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_current_path(&mut self) -> Option<crate::Result<Resource>> {
|
fn next_current_path(&mut self) -> Option<crate::Result<Resource>> {
|
||||||
@ -223,7 +227,7 @@ impl<'a> ResourcePathsIter<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} 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()),
|
("../src/tiles/**/*".into(), "tiles".into()),
|
||||||
("*.toml".into(), "".into()),
|
("*.toml".into(), "".into()),
|
||||||
("*.conf.json".into(), "json".into()),
|
("*.conf.json".into(), "json".into()),
|
||||||
|
("../non-existent-file".into(), "asd".into()), // invalid case
|
||||||
|
("../non/*".into(), "asd".into()), // invalid case
|
||||||
]),
|
]),
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user