From 3f8f1701207b34155c92df94ec1a144eed703161 Mon Sep 17 00:00:00 2001 From: CrLF0710 Date: Wed, 15 Aug 2018 02:08:41 +0800 Subject: [PATCH 1/2] Implement configuration for automatic local bundle loading. --- src/config.rs | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/src/config.rs b/src/config.rs index 3f67c8c8d..e90c7745d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -14,14 +14,16 @@ use std::io::{Read, Write}; use std::io::ErrorKind as IoErrorKind; use std::fs::File; use std::path::PathBuf; +use std::ffi::OsStr; 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; @@ -40,7 +42,6 @@ pub struct BundleInfo { url: String, } - impl PersistentConfig { pub fn open(auto_create_config_file: bool) -> Result { let mut cfg_path = if auto_create_config_file { @@ -74,27 +75,55 @@ impl PersistentConfig { Ok(config) } - pub fn make_cached_url_provider(&self, url: &str, status: &mut StatusBackend) -> Result>> { + pub fn make_cached_url_provider(&self, url: &str, status: &mut StatusBackend) -> Result> { let itb = ITarBundle::::new(url); let mut url2digest_path = app_dir(AppDataType::UserCache, &::APP_INFO, "urls")?; url2digest_path.push(sanitized(url)); - LocalCache::>::new( + let bundle = LocalCache::>::new( itb, &url2digest_path, &app_dir(AppDataType::UserCache, &::APP_INFO, "manifests")?, &app_dir(AppDataType::UserCache, &::APP_INFO, "files")?, - status - ) + status, + )?; + + Ok(Box::new(bundle) as _) + } + + pub fn make_local_file_provider( + &self, + file_path: &OsStr, + _status: &mut StatusBackend, + ) -> Result> { + use std::path::Path; + + let zip_bundle = ZipBundle::::open(Path::new(file_path))?; + + Ok(Box::new(zip_bundle) as _) } pub fn default_bundle(&self, status: &mut StatusBackend) -> Result> { + use std::io; + use hyper::Url; + 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 = Url::parse(&self.default_bundles[0].url) + .map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "failed to parse url"))?; + if url.scheme() == "file" { + // load the local zip file. + let file_path = url.to_file_path() + .map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "failed to parse local path"))?; + let zip_bundle = self.make_local_file_provider(file_path.as_os_str(), status)?; + + return Ok(Box::new(zip_bundle) as _); + } + let bundle = self.make_cached_url_provider(&self.default_bundles[0].url, status)?; + return Ok(Box::new(bundle) as _); } pub fn format_cache_path(&self) -> Result { From 6cddca53266fdfe094a20bc2e956c8f325ed2470 Mon Sep 17 00:00:00 2001 From: CrLF0710 Date: Sun, 19 Aug 2018 00:06:18 +0800 Subject: [PATCH 2/2] Add new unit test. --- tests/tex-outputs.rs | 3 +++ tests/tex-outputs/tex_logo.log | 3 +++ tests/tex-outputs/tex_logo.pdf | Bin 0 -> 1844 bytes tests/tex-outputs/tex_logo.tex | 6 ++++++ tests/tex-outputs/tex_logo.xdv | Bin 0 -> 228 bytes 5 files changed, 12 insertions(+) create mode 100644 tests/tex-outputs/tex_logo.log create mode 100644 tests/tex-outputs/tex_logo.pdf create mode 100644 tests/tex-outputs/tex_logo.tex create mode 100644 tests/tex-outputs/tex_logo.xdv diff --git a/tests/tex-outputs.rs b/tests/tex-outputs.rs index 343ef50a1..96e3bf64d 100644 --- a/tests/tex-outputs.rs +++ b/tests/tex-outputs.rs @@ -194,6 +194,9 @@ fn md5_of_hello() { TestCase::new("md5_of_hello").check_pdf(true).go() } #[test] fn negative_roman_numeral() { TestCase::new("negative_roman_numeral").go() } +#[test] +fn tex_logo() { TestCase::new("tex_logo").go() } + #[test] fn pdfoutput() { TestCase::new("pdfoutput").go() } diff --git a/tests/tex-outputs/tex_logo.log b/tests/tex-outputs/tex_logo.log new file mode 100644 index 000000000..aeabfb223 --- /dev/null +++ b/tests/tex-outputs/tex_logo.log @@ -0,0 +1,3 @@ +** +(tex_logo.tex [1] ) +Output written on tex_logo.xdv (1 page, 228 bytes). diff --git a/tests/tex-outputs/tex_logo.pdf b/tests/tex-outputs/tex_logo.pdf new file mode 100644 index 0000000000000000000000000000000000000000..640368f39225cd2b26ea1d4887e2eb81f095bd1e GIT binary patch literal 1844 zcmai#eKZq_8^>K&tc_W^xZSI@v#f~rYA@d3W+`li;u>k#u3D=Rq7MQ}$z! zcp&1%!t5Fl4@1KugTjC|HYf@^LcokhQ6d-uCYc!=8Nx)lGr2ztLSYyT!OjlI7eq4| z9N?)@j|Uh~hlBQ(iKl^!6l?#ugSl?EfH6F?5R=s0$yXB_fpNtr+@P)5x@S?}H-kHW z-!t{@4x&GB$94~wbojH0mWDSPxB#BN{mT}ijF=dJR+k{E@_TIwtk3pUo zgipaZjccQo|47ri4-Nq`xgq~uznOiy7lZ!iaIcskfsn^Ud2a@c^H+2b3HZ--?3B2< zZ$I+gx%vK+m&5KHs8#}IlT924MxCmLVA}u@H;@qhUB*M$hCEY5rxdug4DQs&&QQ-! zaAN!UYQJPabhs8sL7$V})2nwfF+apaRf0iUgurO3YI=hTPLv)ZL&zte=FMC@7k>As z+^U`(&WLgyIHQYg+qVeOTLNJ0-3HCNlJ1L=`^VepAKOo7Tw0A-Og_#rz7HrQU1 z-Rm7@QFy4TmGf)y*qg~W@SY>15jRWhs0A|jV=Wz>Jg&GcPd*|voT^J zlINjCjcL#Qw!x(=@64GaN#@PE`fyMk{HOsuTkml>F*$9`RFmHY15D;DV5t-Gm@U8L zja>I|N**2yb1U02Xs$1gU5KN!Svp!K*|Oq6Zbx_A z?rA~~nqs@pAH9{Q2k)t6!ZR}%daQ}4&^R@9#WiBC^v4#^GB{rZUDvsG?aV~8 zC_QOk!lE!qRsjP~H^}Ph_&9OJjhy z8ddBCRx1CAn)nskZNKgwk)pHh@D&tHqHOj*n1K?PukS`zB-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