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