Skip to content

Commit d546caa

Browse files
committed
refactor(oma-refresh): improve from logic
1 parent 063b69e commit d546caa

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

oma-refresh/src/sourceslist.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ impl<'a> OmaSourceEntry<'a> {
101101

102102
pub fn from(&self) -> Result<&OmaSourceEntryFrom, RefreshError> {
103103
self.from.get_or_try_init(|| {
104-
let url = self.source.url();
105-
if url.starts_with("http") {
106-
Ok(OmaSourceEntryFrom::Http)
107-
} else if url.starts_with("file") {
108-
Ok(OmaSourceEntryFrom::Local)
109-
} else {
110-
return Err(RefreshError::UnsupportedProtocol(url.to_string()));
104+
let url = Url::parse(self.url())
105+
.map_err(|_| RefreshError::InvalidUrl(self.url().to_string()))?;
106+
107+
match url.scheme() {
108+
"file" => Ok(OmaSourceEntryFrom::Local),
109+
"http" | "https" => Ok(OmaSourceEntryFrom::Http),
110+
x => Err(RefreshError::UnsupportedProtocol(x.to_string())),
111111
}
112112
})
113113
}

0 commit comments

Comments
 (0)