Skip to content

Commit

Permalink
Implement configuration for automatic local bundle loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
crlf0710 committed Aug 15, 2018
1 parent 8a29132 commit 7af6640
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ use app_dirs::{app_dir, app_root, get_app_root, sanitized, AppDataType};
use toml;

use errors::{ErrorKind, Result};
use io::Bundle;
use io::itarbundle::{HttpITarIoFactory, ITarBundle};
use io::local_cache::LocalCache;
use io::zipbundle::ZipBundle;
use io::Bundle;
use status::StatusBackend;


Expand All @@ -40,7 +41,6 @@ pub struct BundleInfo {
url: String,
}


impl PersistentConfig {
pub fn open(auto_create_config_file: bool) -> Result<PersistentConfig> {
let mut cfg_path = if auto_create_config_file {
Expand Down Expand Up @@ -74,7 +74,7 @@ impl PersistentConfig {
Ok(config)
}

pub fn make_cached_url_provider(&self, url: &str, status: &mut StatusBackend) -> Result<LocalCache<ITarBundle<HttpITarIoFactory>>> {
pub fn make_cached_url_provider(&self, url: &str, status: &mut StatusBackend) -> Result<Box<Bundle>> {
let itb = ITarBundle::<HttpITarIoFactory>::new(url);

let mut url2digest_path = app_dir(AppDataType::UserCache, &::APP_INFO, "urls")?;
Expand All @@ -85,16 +85,33 @@ impl PersistentConfig {
&url2digest_path,
&app_dir(AppDataType::UserCache, &::APP_INFO, "manifests")?,
&app_dir(AppDataType::UserCache, &::APP_INFO, "files")?,
status
)
status,
).map(|bundle| Box::new(bundle) as _)
}

pub fn make_local_file_provider(
&self,
url: &str,
_status: &mut StatusBackend,
) -> Result<Box<Bundle>> {
use std::path::Path;

let zb = ZipBundle::<File>::open(Path::new(url))?;

Ok(Box::new(zb) as _)
}

pub fn default_bundle(&self, status: &mut StatusBackend) -> Result<Box<Bundle>> {
if self.default_bundles.len() != 1 {
return Err(ErrorKind::Msg("exactly one default_bundle item must be specified (for now)".to_owned()).into());
}

Ok(Box::new(self.make_cached_url_provider(&self.default_bundles[0].url, status)?))
let url = &self.default_bundles[0].url;
const FILE_SCHEME_PREFIX: &'static str = "file://";
if url.starts_with(FILE_SCHEME_PREFIX) {
return Ok(self.make_local_file_provider(&url[FILE_SCHEME_PREFIX.len()..], status)?);
}
Ok(self.make_cached_url_provider(&self.default_bundles[0].url, status)?)
}

pub fn format_cache_path(&self) -> Result<PathBuf> {
Expand Down

0 comments on commit 7af6640

Please sign in to comment.