diff --git a/garnet/bin/omaha_client/src/install_plan.rs b/garnet/bin/omaha_client/src/install_plan.rs index 31e9292e39c8b71c92269ba22ba89a35d53a3d67..71195bc8a4270b76094f31796b9925031f1352e0 100644 --- a/garnet/bin/omaha_client/src/install_plan.rs +++ b/garnet/bin/omaha_client/src/install_plan.rs @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -use fuchsia_uri::pkg_uri::FuchsiaPkgUri; +use fuchsia_uri::pkg_uri::PkgUri; use log::{error, info, warn}; use omaha_client::install_plan::InstallPlan; use omaha_client::protocol::response::{OmahaStatus, Response}; @@ -10,7 +10,7 @@ use omaha_client::protocol::response::{OmahaStatus, Response}; #[derive(Debug, PartialEq)] pub struct FuchsiaInstallPlan { /// The fuchsia TUF repo URI, e.g. fuchsia-pkg://fuchsia.com/update/0?hash=... - pub uri: FuchsiaPkgUri, + pub uri: PkgUri, } impl InstallPlan for FuchsiaInstallPlan { @@ -70,10 +70,10 @@ impl InstallPlan for FuchsiaInstallPlan { warn!("Only 1 url is supported, found {}", urls.len()); } - match FuchsiaPkgUri::parse(&url.codebase) { + match PkgUri::parse(&url.codebase) { Ok(uri) => Some(FuchsiaInstallPlan { uri: uri }), Err(err) => { - error!("Failed to parse {} to FuchsiaPkgUri: {}", url.codebase, err); + error!("Failed to parse {} to PkgUri: {}", url.codebase, err); None } } diff --git a/garnet/bin/pkg_resolver/src/resolver_service.rs b/garnet/bin/pkg_resolver/src/resolver_service.rs index 0c9ec93d7cfcbf8e890544b8a9563ce39dc948c5..4501a50f1d74f0a9e42b82aed7b212b2dc236d89 100644 --- a/garnet/bin/pkg_resolver/src/resolver_service.rs +++ b/garnet/bin/pkg_resolver/src/resolver_service.rs @@ -14,7 +14,7 @@ use fidl_fuchsia_pkg_ext::BlobId; use fuchsia_async as fasync; use fuchsia_component::client::connect_to_service; use fuchsia_syslog::{fx_log_err, fx_log_info, fx_log_warn}; -use fuchsia_uri::pkg_uri::FuchsiaPkgUri; +use fuchsia_uri::pkg_uri::PkgUri; use fuchsia_zircon::{Channel, MessageBuf, Signals, Status}; use futures::prelude::*; use lazy_static::lazy_static; @@ -72,7 +72,7 @@ pub async fn run_resolver_service( Ok(()) } -fn rewrite_uri(rewrites: &Arc<RwLock<RewriteManager>>, uri: FuchsiaPkgUri) -> FuchsiaPkgUri { +fn rewrite_uri(rewrites: &Arc<RwLock<RewriteManager>>, uri: PkgUri) -> PkgUri { for rule in rewrites.read().list() { match rule.apply(&uri) { Some(Ok(res)) => { @@ -100,7 +100,7 @@ async fn resolve<'a>( _update_policy: UpdatePolicy, dir_request: ServerEnd<DirectoryMarker>, ) -> Result<(), Status> { - let uri = FuchsiaPkgUri::parse(&pkg_uri).map_err(|err| { + let uri = PkgUri::parse(&pkg_uri).map_err(|err| { fx_log_err!("failed to parse package uri {:?}: {}", pkg_uri, err); Err(Status::INVALID_ARGS) })?; @@ -162,7 +162,7 @@ async fn resolve<'a>( Ok(()) } -async fn wait_for_update_to_complete(chan: Channel, uri: &FuchsiaPkgUri) -> Result<BlobId, Status> { +async fn wait_for_update_to_complete(chan: Channel, uri: &PkgUri) -> Result<BlobId, Status> { let mut buf = MessageBuf::new(); let sigs = await!(fasync::OnSignals::new( @@ -485,12 +485,9 @@ mod tests { Some(variant) => format!("/{}/{}", name, variant), }; - let uri = FuchsiaPkgUri::new_package( - "fuchsia.com".to_string(), - path, - merkle.map(|s| s.to_string()), - ) - .unwrap(); + let uri = + PkgUri::new_package("fuchsia.com".to_string(), path, merkle.map(|s| s.to_string())) + .unwrap(); let res = await!(wait_for_update_to_complete(chan, &uri)); assert_eq!(res, expected_res); diff --git a/garnet/bin/sys/component_manager/src/fuchsia_boot_resolver.rs b/garnet/bin/sys/component_manager/src/fuchsia_boot_resolver.rs index 157cbf34af41652ea92ab3e4ecd5a61709c5c1e0..5aa630c26e3cf9d48b926261f29de0a498f7728d 100644 --- a/garnet/bin/sys/component_manager/src/fuchsia_boot_resolver.rs +++ b/garnet/bin/sys/component_manager/src/fuchsia_boot_resolver.rs @@ -8,7 +8,7 @@ use { cm_fidl_translator::translate, fidl::endpoints::ClientEnd, fidl_fuchsia_sys2 as fsys, - fuchsia_uri::boot_uri::FuchsiaBootUri, + fuchsia_uri::boot_uri::BootUri, futures::future::FutureObj, std::path::PathBuf, }; @@ -31,7 +31,7 @@ impl FuchsiaBootResolver { component_uri: &'a str, ) -> Result<fsys::Component, ResolverError> { // Parse URI. - let uri = FuchsiaBootUri::parse(component_uri) + let uri = BootUri::parse(component_uri) .map_err(|e| ResolverError::component_not_available(component_uri, e))?; let res = uri.resource().ok_or(ResolverError::uri_missing_resource_error(component_uri))?; let res_path = PathBuf::from(uri.path()).join(PathBuf::from(res)); diff --git a/garnet/bin/sys/component_manager/src/fuchsia_pkg_resolver.rs b/garnet/bin/sys/component_manager/src/fuchsia_pkg_resolver.rs index dee74b41d902b3ea875fd08c0eb363b5df70e0b3..9d8e1eee2a9827dd806542ab1f26bc6f6a7a2f29 100644 --- a/garnet/bin/sys/component_manager/src/fuchsia_pkg_resolver.rs +++ b/garnet/bin/sys/component_manager/src/fuchsia_pkg_resolver.rs @@ -11,7 +11,7 @@ use { fidl_fuchsia_io::DirectoryMarker, fidl_fuchsia_pkg::{PackageResolverProxy, UpdatePolicy}, fidl_fuchsia_sys2 as fsys, - fuchsia_uri::pkg_uri::FuchsiaPkgUri, + fuchsia_uri::pkg_uri::PkgUri, fuchsia_zircon as zx, futures::future::FutureObj, std::path::PathBuf, @@ -35,7 +35,7 @@ impl FuchsiaPkgResolver { component_uri: &'a str, ) -> Result<fsys::Component, ResolverError> { // Parse URI. - let fuchsia_pkg_uri = FuchsiaPkgUri::parse(component_uri) + let fuchsia_pkg_uri = PkgUri::parse(component_uri) .map_err(|e| ResolverError::uri_parse_error(component_uri, e))?; fuchsia_pkg_uri .resource() @@ -141,7 +141,7 @@ mod tests { package_uri: &str, dir: fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>, ) -> Result<(), zx::Status> { - let package_uri = FuchsiaPkgUri::parse(&package_uri).expect("bad uri"); + let package_uri = PkgUri::parse(&package_uri).expect("bad uri"); if package_uri.name().unwrap() != "hello_world" { return Err(zx::Status::NOT_FOUND); } diff --git a/garnet/bin/sys/component_manager/tests/mock_pkg_resolver.rs b/garnet/bin/sys/component_manager/tests/mock_pkg_resolver.rs index 531baa5851063c3778b5baeda283b90b977fd76f..d10632e9c0edcda2c09b11c941cf36420e8ff9f0 100644 --- a/garnet/bin/sys/component_manager/tests/mock_pkg_resolver.rs +++ b/garnet/bin/sys/component_manager/tests/mock_pkg_resolver.rs @@ -12,7 +12,7 @@ use { fidl_fuchsia_pkg as fpkg, fuchsia_async as fasync, fuchsia_component::server::ServiceFs, fuchsia_syslog::{self, macros::*}, - fuchsia_uri::pkg_uri::FuchsiaPkgUri, + fuchsia_uri::pkg_uri::PkgUri, fuchsia_zircon::{HandleBased, Status}, futures::{StreamExt, TryStreamExt}, std::ffi::CString, @@ -50,7 +50,7 @@ async fn run_resolver_service(mut stream: fpkg::PackageResolverRequestStream) -> } async fn resolve(package_uri: String, dir: ServerEnd<DirectoryMarker>) -> Result<(), Status> { - let uri = FuchsiaPkgUri::parse(&package_uri).map_err(|_| Err(Status::INVALID_ARGS))?; + let uri = PkgUri::parse(&package_uri).map_err(|_| Err(Status::INVALID_ARGS))?; let name = uri.name().ok_or_else(|| Err(Status::INVALID_ARGS))?; if name != "routing_integration_test" { return Err(Status::NOT_FOUND); diff --git a/garnet/lib/rust/fidl_fuchsia_pkg_ext/src/repo.rs b/garnet/lib/rust/fidl_fuchsia_pkg_ext/src/repo.rs index 19da968875fb406050fcfcb09e2e32acff0360b1..8188d20e1ea8a6b6460f9a611f36ff67c0781f1a 100644 --- a/garnet/lib/rust/fidl_fuchsia_pkg_ext/src/repo.rs +++ b/garnet/lib/rust/fidl_fuchsia_pkg_ext/src/repo.rs @@ -5,7 +5,7 @@ use { crate::errors::RepositoryParseError, fidl_fuchsia_pkg as fidl, - fuchsia_uri::pkg_uri::{FuchsiaPkgUri, RepoUri}, + fuchsia_uri::pkg_uri::{PkgUri, RepoUri}, serde_derive::{Deserialize, Serialize}, std::convert::TryFrom, std::mem, @@ -93,7 +93,7 @@ pub struct RepositoryConfig { repo_url: RepoUri, root_keys: Vec<RepositoryKey>, mirrors: Vec<MirrorConfig>, - update_package_uri: Option<FuchsiaPkgUri>, + update_package_uri: Option<PkgUri>, } impl RepositoryConfig { @@ -195,7 +195,7 @@ impl RepositoryConfigBuilder { self } - pub fn update_package_uri(mut self, uri: FuchsiaPkgUri) -> Self { + pub fn update_package_uri(mut self, uri: PkgUri) -> Self { self.config.update_package_uri = Some(uri); self } diff --git a/garnet/lib/rust/fuchsia_uri/src/boot_uri.rs b/garnet/lib/rust/fuchsia_uri/src/boot_uri.rs index 7a05d0de6b4b2b546e03c01d4ac15e393ac9bfe3..5c69bce63312a7354010512b5f69413716e792e2 100644 --- a/garnet/lib/rust/fuchsia_uri/src/boot_uri.rs +++ b/garnet/lib/rust/fuchsia_uri/src/boot_uri.rs @@ -12,12 +12,12 @@ use url::Url; /// /// fuchsia-boot:///path/to#path/to/resource #[derive(Clone, Debug, PartialEq, Eq)] -pub struct FuchsiaBootUri { +pub struct BootUri { path: String, resource: Option<String>, } -impl FuchsiaBootUri { +impl BootUri { pub fn parse(input: &str) -> Result<Self, ParseError> { let uri = Url::parse(input)?; @@ -69,7 +69,7 @@ impl FuchsiaBootUri { None => None, }; - Ok(FuchsiaBootUri { path, resource }) + Ok(BootUri { path, resource }) } pub fn path(&self) -> &str { @@ -80,16 +80,16 @@ impl FuchsiaBootUri { self.resource.as_ref().map(|s| s.as_str()) } - pub fn root_uri(&self) -> FuchsiaBootUri { - FuchsiaBootUri { path: self.path.clone(), resource: None } + pub fn root_uri(&self) -> BootUri { + BootUri { path: self.path.clone(), resource: None } } - pub fn new_path(path: String) -> Result<FuchsiaBootUri, ParseError> { - Ok(FuchsiaBootUri { path: path.clone(), resource: None }) + pub fn new_path(path: String) -> Result<BootUri, ParseError> { + Ok(BootUri { path: path.clone(), resource: None }) } - pub fn new_resource(path: String, resource: String) -> Result<FuchsiaBootUri, ParseError> { - let mut uri = FuchsiaBootUri::new_path(path)?; + pub fn new_resource(path: String, resource: String) -> Result<BootUri, ParseError> { + let mut uri = BootUri::new_path(path)?; if resource.is_empty() || !check_resource(&resource) { return Err(ParseError::InvalidResourcePath); } @@ -98,7 +98,7 @@ impl FuchsiaBootUri { } } -impl fmt::Display for FuchsiaBootUri { +impl fmt::Display for BootUri { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "fuchsia-boot://{}", self.path)?; if let Some(ref resource) = self.resource { @@ -135,8 +135,8 @@ mod tests { fn $test_name() { let pkg_uri = $pkg_uri.to_string(); assert_eq!( - FuchsiaBootUri::parse(&pkg_uri), - Ok(FuchsiaBootUri { + BootUri::parse(&pkg_uri), + Ok(BootUri { path: $pkg_path, resource: $pkg_resource, }) @@ -160,7 +160,7 @@ mod tests { fn $test_name() { for uri in &$uris { assert_eq!( - FuchsiaBootUri::parse(uri), + BootUri::parse(uri), Err($err), ); } @@ -318,18 +318,18 @@ mod tests { test_format! { test_format_path_uri => { - parsed = FuchsiaBootUri::new_path("/path/to".to_string()).unwrap(), + parsed = BootUri::new_path("/path/to".to_string()).unwrap(), formatted = "fuchsia-boot:///path/to", } test_format_resource_uri => { - parsed = FuchsiaBootUri::new_resource("/path/to".to_string(), "path/to/resource".to_string()).unwrap(), + parsed = BootUri::new_resource("/path/to".to_string(), "path/to/resource".to_string()).unwrap(), formatted = "fuchsia-boot:///path/to#path/to/resource", } } #[test] fn test_new_path() { - let uri = FuchsiaBootUri::new_path("/path/to".to_string()).unwrap(); + let uri = BootUri::new_path("/path/to".to_string()).unwrap(); assert_eq!("/path/to", uri.path()); assert_eq!(None, uri.resource()); assert_eq!(uri, uri.root_uri()); @@ -339,7 +339,7 @@ mod tests { #[test] fn test_new_resource() { let uri = - FuchsiaBootUri::new_resource("/path/to".to_string(), "foo/bar".to_string()).unwrap(); + BootUri::new_resource("/path/to".to_string(), "foo/bar".to_string()).unwrap(); assert_eq!("/path/to", uri.path()); assert_eq!(Some("foo/bar"), uri.resource()); let mut uri_no_resource = uri.clone(); diff --git a/garnet/lib/rust/fuchsia_uri/src/pkg_uri.rs b/garnet/lib/rust/fuchsia_uri/src/pkg_uri.rs index 42bb37c32e1f6e1bb7e7e4fb5fd62cb7e2871031..3b44984c47b8f1d45be17112a63d17d2e4dd5776 100644 --- a/garnet/lib/rust/fuchsia_uri/src/pkg_uri.rs +++ b/garnet/lib/rust/fuchsia_uri/src/pkg_uri.rs @@ -33,14 +33,14 @@ use url::Url; /// - fuchsia-pkg://example.com/some-package/some-variant?hash=<some-hash>#path/to/resource /// - fuchsia-pkg://example.com/some-package/some-variant/<some-hash>#path/to/resource (obsolete) #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] -pub struct FuchsiaPkgUri { +pub struct PkgUri { host: String, path: String, hash: Option<String>, resource: Option<String>, } -impl FuchsiaPkgUri { +impl PkgUri { pub fn parse(input: &str) -> Result<Self, ParseError> { let uri = Url::parse(input)?; @@ -94,7 +94,7 @@ impl FuchsiaPkgUri { None }; - Ok(FuchsiaPkgUri { host, path, hash, resource }) + Ok(PkgUri { host, path, hash, resource }) } pub fn host(&self) -> &str { @@ -111,7 +111,7 @@ impl FuchsiaPkgUri { self.path[1..].split_terminator('/').nth(1) } - /// Produce a string representation of the package referenced by this [FuchsiaPkgUri]. + /// Produce a string representation of the package referenced by this [PkgUri]. pub fn path(&self) -> &str { &self.path } @@ -130,9 +130,9 @@ impl FuchsiaPkgUri { self.path == "/" && self.hash.is_none() && self.resource.is_none() } - /// Produce a new [FuchsiaPkgUri] with any resource fragment stripped off. - pub fn root_uri(&self) -> FuchsiaPkgUri { - FuchsiaPkgUri { + /// Produce a new [PkgUri] with any resource fragment stripped off. + pub fn root_uri(&self) -> PkgUri { + PkgUri { host: self.host.clone(), path: self.path.clone(), hash: self.hash.clone(), @@ -140,25 +140,20 @@ impl FuchsiaPkgUri { } } - pub fn new_repository(host: String) -> Result<FuchsiaPkgUri, ParseError> { + pub fn new_repository(host: String) -> Result<PkgUri, ParseError> { if host.is_empty() { return Err(ParseError::InvalidHost); } - Ok(FuchsiaPkgUri { - host: host.to_string(), - path: "/".to_string(), - hash: None, - resource: None, - }) + Ok(PkgUri { host: host.to_string(), path: "/".to_string(), hash: None, resource: None }) } pub fn new_package( host: String, path: String, hash: Option<String>, - ) -> Result<FuchsiaPkgUri, ParseError> { - let mut uri = FuchsiaPkgUri::new_repository(host)?; + ) -> Result<PkgUri, ParseError> { + let mut uri = PkgUri::new_repository(host)?; let (name, variant) = parse_path(path.as_str())?; @@ -184,8 +179,8 @@ impl FuchsiaPkgUri { path: String, hash: Option<String>, resource: String, - ) -> Result<FuchsiaPkgUri, ParseError> { - let mut uri = FuchsiaPkgUri::new_package(host, path, hash)?; + ) -> Result<PkgUri, ParseError> { + let mut uri = PkgUri::new_package(host, path, hash)?; if resource.is_empty() || !check_resource(&resource) { return Err(ParseError::InvalidResourcePath); } @@ -194,7 +189,7 @@ impl FuchsiaPkgUri { } } -impl fmt::Display for FuchsiaPkgUri { +impl fmt::Display for PkgUri { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "fuchsia-pkg://{}", self.host)?; if self.path != "/" { @@ -219,51 +214,51 @@ impl fmt::Display for FuchsiaPkgUri { } } -impl str::FromStr for FuchsiaPkgUri { +impl str::FromStr for PkgUri { type Err = ParseError; fn from_str(value: &str) -> Result<Self, Self::Err> { - FuchsiaPkgUri::parse(value) + PkgUri::parse(value) } } -impl TryFrom<&str> for FuchsiaPkgUri { +impl TryFrom<&str> for PkgUri { type Error = ParseError; fn try_from(value: &str) -> Result<Self, Self::Error> { - FuchsiaPkgUri::parse(value) + PkgUri::parse(value) } } -impl Serialize for FuchsiaPkgUri { +impl Serialize for PkgUri { fn serialize<S: Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> { self.to_string().serialize(ser) } } -impl<'de> Deserialize<'de> for FuchsiaPkgUri { +impl<'de> Deserialize<'de> for PkgUri { fn deserialize<D>(de: D) -> Result<Self, D::Error> where D: Deserializer<'de>, { let uri = String::deserialize(de)?; - Ok(FuchsiaPkgUri::parse(&uri).map_err(|err| serde::de::Error::custom(err))?) + Ok(PkgUri::parse(&uri).map_err(|err| serde::de::Error::custom(err))?) } } #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize)] #[serde(transparent)] pub struct RepoUri { - uri: FuchsiaPkgUri, + uri: PkgUri, } impl RepoUri { pub fn new(host: String) -> Result<Self, ParseError> { - Ok(RepoUri { uri: FuchsiaPkgUri::new_repository(host)? }) + Ok(RepoUri { uri: PkgUri::new_repository(host)? }) } pub fn parse(input: &str) -> Result<Self, ParseError> { - let uri = FuchsiaPkgUri::parse(input)?; + let uri = PkgUri::parse(input)?; RepoUri::try_from(uri) } @@ -288,10 +283,10 @@ impl TryFrom<&str> for RepoUri { } } -impl TryFrom<FuchsiaPkgUri> for RepoUri { +impl TryFrom<PkgUri> for RepoUri { type Error = ParseError; - fn try_from(uri: FuchsiaPkgUri) -> Result<Self, Self::Error> { + fn try_from(uri: PkgUri) -> Result<Self, Self::Error> { if uri.is_repository() { Ok(RepoUri { uri }) } else { @@ -300,7 +295,7 @@ impl TryFrom<FuchsiaPkgUri> for RepoUri { } } -impl From<RepoUri> for FuchsiaPkgUri { +impl From<RepoUri> for PkgUri { fn from(uri: RepoUri) -> Self { uri.uri } @@ -316,7 +311,7 @@ impl fmt::Display for RepoUri { // be a repository URI. impl<'de> Deserialize<'de> for RepoUri { fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, D::Error> { - let uri = FuchsiaPkgUri::deserialize(de)?; + let uri = PkgUri::deserialize(de)?; Ok(RepoUri::try_from(uri).map_err(|err| serde::de::Error::custom(err))?) } } @@ -400,10 +395,10 @@ mod tests { #[test] fn test_eq() { let pkg_uri = $pkg_uri.to_string(); - let uri = FuchsiaPkgUri::parse(&pkg_uri); + let uri = PkgUri::parse(&pkg_uri); assert_eq!( uri, - Ok(FuchsiaPkgUri { + Ok(PkgUri { host: $pkg_host.to_string(), path: $pkg_path.to_string(), hash: $pkg_hash.map(|s: &str| s.to_string()), @@ -422,10 +417,10 @@ mod tests { #[test] fn test_roundtrip() { let pkg_uri = $pkg_uri.to_string(); - let parsed = FuchsiaPkgUri::parse(&pkg_uri).unwrap(); + let parsed = PkgUri::parse(&pkg_uri).unwrap(); let format_pkg_uri = parsed.to_string(); assert_eq!( - FuchsiaPkgUri::parse(&format_pkg_uri), + PkgUri::parse(&format_pkg_uri), Ok(parsed) ); } @@ -448,7 +443,7 @@ mod tests { fn $test_name() { for uri in &$uris { assert_eq!( - FuchsiaPkgUri::parse(uri), + PkgUri::parse(uri), Err($err), ); } @@ -713,11 +708,11 @@ mod tests { test_format! { test_format_repository_uri => { - parsed = FuchsiaPkgUri::new_repository("fuchsia.com".to_string()).unwrap(), + parsed = PkgUri::new_repository("fuchsia.com".to_string()).unwrap(), formatted = "fuchsia-pkg://fuchsia.com", } test_format_package_uri => { - parsed = FuchsiaPkgUri::new_package( + parsed = PkgUri::new_package( "fuchsia.com".to_string(), "/fonts".to_string(), None, @@ -725,7 +720,7 @@ mod tests { formatted = "fuchsia-pkg://fuchsia.com/fonts", } test_format_package_uri_with_variant => { - parsed = FuchsiaPkgUri::new_package( + parsed = PkgUri::new_package( "fuchsia.com".to_string(), "/fonts/stable".to_string(), None, @@ -733,7 +728,7 @@ mod tests { formatted = "fuchsia-pkg://fuchsia.com/fonts/stable", } test_format_package_uri_with_hash => { - parsed = FuchsiaPkgUri::new_package( + parsed = PkgUri::new_package( "fuchsia.com".to_string(), "/fonts/stable".to_string(), Some("80e8721f4eba5437c8b6e1604f6ee384f42aed2b6dfbfd0b616a864839cd7b4a".to_string()), @@ -741,7 +736,7 @@ mod tests { formatted = "fuchsia-pkg://fuchsia.com/fonts/stable?hash=80e8721f4eba5437c8b6e1604f6ee384f42aed2b6dfbfd0b616a864839cd7b4a", } test_format_resource_uri => { - parsed = FuchsiaPkgUri::new_resource( + parsed = PkgUri::new_resource( "fuchsia.com".to_string(), "/fonts".to_string(), None, @@ -753,7 +748,7 @@ mod tests { #[test] fn test_new_repository() { - let uri = FuchsiaPkgUri::new_repository("fuchsia.com".to_string()).unwrap(); + let uri = PkgUri::new_repository("fuchsia.com".to_string()).unwrap(); assert_eq!("fuchsia.com", uri.host()); assert_eq!("/", uri.path()); assert_eq!(None, uri.name()); @@ -761,12 +756,12 @@ mod tests { assert_eq!(None, uri.hash()); assert_eq!(None, uri.resource()); - assert_eq!(FuchsiaPkgUri::new_repository("".to_string()), Err(ParseError::InvalidHost)); + assert_eq!(PkgUri::new_repository("".to_string()), Err(ParseError::InvalidHost)); } #[test] fn test_new_package() { - let uri = FuchsiaPkgUri::new_package( + let uri = PkgUri::new_package( "fuchsia.com".to_string(), "/fonts/stable".to_string(), Some("80e8721f4eba5437c8b6e1604f6ee384f42aed2b6dfbfd0b616a864839cd7b4a".to_string()), @@ -784,23 +779,23 @@ mod tests { assert_eq!(uri, uri.root_uri()); assert_eq!( - FuchsiaPkgUri::new_package("".to_string(), "/fonts".to_string(), None), + PkgUri::new_package("".to_string(), "/fonts".to_string(), None), Err(ParseError::InvalidHost) ); assert_eq!( - FuchsiaPkgUri::new_package("fuchsia.com".to_string(), "fonts".to_string(), None), + PkgUri::new_package("fuchsia.com".to_string(), "fonts".to_string(), None), Err(ParseError::InvalidPath) ); assert_eq!( - FuchsiaPkgUri::new_package("fuchsia.com".to_string(), "/".to_string(), None), + PkgUri::new_package("fuchsia.com".to_string(), "/".to_string(), None), Err(ParseError::InvalidName) ); assert_eq!( - FuchsiaPkgUri::new_package("fuchsia.com".to_string(), "/fonts/$".to_string(), None), + PkgUri::new_package("fuchsia.com".to_string(), "/fonts/$".to_string(), None), Err(ParseError::InvalidVariant) ); assert_eq!( - FuchsiaPkgUri::new_package( + PkgUri::new_package( "fuchsia.com".to_string(), "/fonts".to_string(), Some( @@ -810,7 +805,7 @@ mod tests { Err(ParseError::InvalidVariant) ); assert_eq!( - FuchsiaPkgUri::new_package( + PkgUri::new_package( "fuchsia.com".to_string(), "/fonts/stable".to_string(), Some("$".to_string()) @@ -821,7 +816,7 @@ mod tests { #[test] fn test_new_resource() { - let uri = FuchsiaPkgUri::new_resource( + let uri = PkgUri::new_resource( "fuchsia.com".to_string(), "/fonts/stable".to_string(), Some("80e8721f4eba5437c8b6e1604f6ee384f42aed2b6dfbfd0b616a864839cd7b4a".to_string()), @@ -842,16 +837,11 @@ mod tests { assert_eq!(uri_no_resource, uri.root_uri()); assert_eq!( - FuchsiaPkgUri::new_resource( - "".to_string(), - "/fonts".to_string(), - None, - "foo/bar".to_string() - ), + PkgUri::new_resource("".to_string(), "/fonts".to_string(), None, "foo/bar".to_string()), Err(ParseError::InvalidHost) ); assert_eq!( - FuchsiaPkgUri::new_resource( + PkgUri::new_resource( "fuchsia.com".to_string(), "/".to_string(), None, @@ -860,7 +850,7 @@ mod tests { Err(ParseError::InvalidName) ); assert_eq!( - FuchsiaPkgUri::new_resource( + PkgUri::new_resource( "fuchsia.com".to_string(), "/fonts/$".to_string(), None, @@ -869,7 +859,7 @@ mod tests { Err(ParseError::InvalidVariant) ); assert_eq!( - FuchsiaPkgUri::new_resource( + PkgUri::new_resource( "fuchsia.com".to_string(), "/fonts".to_string(), Some( @@ -880,7 +870,7 @@ mod tests { Err(ParseError::InvalidVariant) ); assert_eq!( - FuchsiaPkgUri::new_resource( + PkgUri::new_resource( "fuchsia.com".to_string(), "/fonts/stable".to_string(), Some("$".to_string()), @@ -889,7 +879,7 @@ mod tests { Err(ParseError::InvalidHash) ); assert_eq!( - FuchsiaPkgUri::new_resource( + PkgUri::new_resource( "fuchsia.com".to_string(), "/fonts".to_string(), None, @@ -898,7 +888,7 @@ mod tests { Err(ParseError::InvalidResourcePath) ); assert_eq!( - FuchsiaPkgUri::new_resource( + PkgUri::new_resource( "fuchsia.com".to_string(), "/fonts".to_string(), None, @@ -910,7 +900,7 @@ mod tests { #[test] fn test_repo_uri() { - let parsed_pkg_uri = FuchsiaPkgUri::new_repository("fuchsia.com".to_string()).unwrap(); + let parsed_pkg_uri = PkgUri::new_repository("fuchsia.com".to_string()).unwrap(); let parsed_repo_uri = RepoUri::new("fuchsia.com".to_string()).unwrap(); let uris = &["fuchsia-pkg://fuchsia.com", "fuchsia-pkg://fuchsia.com/"]; diff --git a/garnet/lib/rust/fuchsia_uri_rewrite/src/rule.rs b/garnet/lib/rust/fuchsia_uri_rewrite/src/rule.rs index eef13cea361fd8ecc33b1499fb527283ca6517b3..60835d7c5c0f3846925718ccea6252c9da22ca0f 100644 --- a/garnet/lib/rust/fuchsia_uri_rewrite/src/rule.rs +++ b/garnet/lib/rust/fuchsia_uri_rewrite/src/rule.rs @@ -5,12 +5,12 @@ use { crate::errors::{RuleDecodeError, RuleParseError}, fidl_fuchsia_pkg_rewrite as fidl, - fuchsia_uri::pkg_uri::{FuchsiaPkgUri, ParseError}, + fuchsia_uri::pkg_uri::{ParseError, PkgUri}, serde_derive::{Deserialize, Serialize}, std::convert::TryFrom, }; -/// A `Rule` can be used to re-write parts of a [`FuchsiaPkgUri`]. +/// A `Rule` can be used to re-write parts of a [`PkgUri`]. #[derive(Debug, Clone, PartialEq, Eq, Serialize)] pub struct Rule { host_match: String, @@ -36,8 +36,7 @@ impl Rule { path_prefix_replacement: String, ) -> Result<Self, RuleParseError> { fn validate_host(s: &str) -> Result<(), RuleParseError> { - FuchsiaPkgUri::new_repository(s.to_owned()) - .map_err(|_err| RuleParseError::InvalidHost)?; + PkgUri::new_repository(s.to_owned()).map_err(|_err| RuleParseError::InvalidHost)?; Ok(()) } @@ -60,7 +59,7 @@ impl Rule { Ok(Self { host_match, host_replacement, path_prefix_match, path_prefix_replacement }) } - /// Apply this `Rule` to the given [`FuchsiaPkgUri`]. + /// Apply this `Rule` to the given [`PkgUri`]. /// /// In order for a `Rule` to match a particular fuchsia-pkg:// URI, `host` must match `uri`'s /// host exactly and `path` must prefix match the `uri`'s path at a '/' boundary. If `path` @@ -69,7 +68,7 @@ impl Rule { /// When a `Rule` does match the given `uri`, it will replace the matched hostname and path /// with the given replacement strings, preserving the unmatched part of the path, the hash /// query parameter, and any fragment. - pub fn apply(&self, uri: &FuchsiaPkgUri) -> Option<Result<FuchsiaPkgUri, ParseError>> { + pub fn apply(&self, uri: &PkgUri) -> Option<Result<PkgUri, ParseError>> { if uri.host() != self.host_match { return None; } @@ -92,15 +91,15 @@ impl Rule { }; Some(match (new_path.as_str(), uri.resource()) { - ("/", _) => FuchsiaPkgUri::new_repository(self.host_replacement.clone()), + ("/", _) => PkgUri::new_repository(self.host_replacement.clone()), - (_, None) => FuchsiaPkgUri::new_package( + (_, None) => PkgUri::new_package( self.host_replacement.clone(), new_path, uri.hash().map(|s| s.to_owned()), ), - (_, Some(resource)) => FuchsiaPkgUri::new_resource( + (_, Some(resource)) => PkgUri::new_resource( self.host_replacement.clone(), new_path, uri.hash().map(|s| s.to_owned()), @@ -392,10 +391,10 @@ mod rule_tests { .unwrap(); $( - let input = FuchsiaPkgUri::parse($input).unwrap(); + let input = PkgUri::parse($input).unwrap(); let output: Option<Result<&str, ParseError>> = $output; - let output: Option<Result<FuchsiaPkgUri, _>> = match output { - Some(Ok(s)) => Some(Ok(FuchsiaPkgUri::parse(s).unwrap())), + let output: Option<Result<PkgUri, _>> = match output { + Some(Ok(s)) => Some(Ok(PkgUri::parse(s).unwrap())), Some(Err(x)) => Some(Err(x)), None => None, };