use crate::error::{self, Result};
use snafu::ResultExt;
use std::path::Path;
use tough::{Repository, RepositoryLoader};
use url::Url;
pub(crate) const UNUSED_URL: &str = "file:///unused/url";
pub(crate) async fn load_metadata_repo<P>(root: P, metadata_url: Url) -> Result<Repository>
where
P: AsRef<Path>,
{
let root = root.as_ref();
RepositoryLoader::new(
&tokio::fs::read(root)
.await
.context(error::OpenRootSnafu { path: root })?,
metadata_url,
Url::parse(UNUSED_URL).with_context(|_| error::UrlParseSnafu {
url: UNUSED_URL.to_owned(),
})?,
)
.load()
.await
.context(error::RepoLoadSnafu)
}