Skip to content

Commit 8c737b9

Browse files
authored
Merge pull request #203 from rekka/feat-only-cached
Add --only-cached/-C command line flag
2 parents 8a29132 + d0ea85d commit 8c737b9

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

src/bin/tectonic.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,17 @@ fn inner(args: ArgMatches, config: PersistentConfig, status: &mut TermcolorStatu
101101
}
102102
}
103103

104+
let only_cached = args.is_present("only_cached");
105+
if only_cached {
106+
tt_note!(status, "using only cached resource files");
107+
}
104108
if let Some(p) = args.value_of("bundle") {
105109
let zb = ctry!(ZipBundle::<File>::open(Path::new(&p)); "error opening bundle");
106110
sess_builder.bundle(Box::new(zb));
107111
} else if let Some(u) = args.value_of("web_bundle") {
108-
sess_builder.bundle(Box::new(config.make_cached_url_provider(&u, status)?));
112+
sess_builder.bundle(Box::new(config.make_cached_url_provider(&u, only_cached, status)?));
109113
} else {
110-
sess_builder.bundle(config.default_bundle(status)?);
114+
sess_builder.bundle(config.default_bundle(only_cached, status)?);
111115
}
112116

113117
let mut sess = sess_builder.create(status)?;
@@ -149,6 +153,10 @@ fn main() {
149153
.value_name("URL")
150154
.help("Use this URL find resource files instead of the default")
151155
.takes_value(true))
156+
.arg(Arg::with_name("only_cached")
157+
.short("C")
158+
.long("only-cached")
159+
.help("Use only resource files cached locally"))
152160
.arg(Arg::with_name("outfmt")
153161
.long("outfmt")
154162
.value_name("FORMAT")

src/config.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl PersistentConfig {
7474
Ok(config)
7575
}
7676

77-
pub fn make_cached_url_provider(&self, url: &str, status: &mut StatusBackend) -> Result<LocalCache<ITarBundle<HttpITarIoFactory>>> {
77+
pub fn make_cached_url_provider(&self, url: &str, only_cached: bool, status: &mut StatusBackend) -> Result<LocalCache<ITarBundle<HttpITarIoFactory>>> {
7878
let itb = ITarBundle::<HttpITarIoFactory>::new(url);
7979

8080
let mut url2digest_path = app_dir(AppDataType::UserCache, &::APP_INFO, "urls")?;
@@ -85,16 +85,17 @@ impl PersistentConfig {
8585
&url2digest_path,
8686
&app_dir(AppDataType::UserCache, &::APP_INFO, "manifests")?,
8787
&app_dir(AppDataType::UserCache, &::APP_INFO, "files")?,
88+
only_cached,
8889
status
8990
)
9091
}
9192

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

97-
Ok(Box::new(self.make_cached_url_provider(&self.default_bundles[0].url, status)?))
98+
Ok(Box::new(self.make_cached_url_provider(&self.default_bundles[0].url, only_cached, status)?))
9899
}
99100

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

src/io/local_cache.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ pub struct LocalCache<B: Bundle> {
3131
manifest_path: PathBuf,
3232
data_path: PathBuf,
3333
contents: HashMap<OsString,LocalCacheItem>,
34+
only_cached: bool,
3435
}
3536

3637

3738
impl<B: Bundle> LocalCache<B> {
3839
pub fn new(
3940
mut backend: B, digest: &Path, manifest_base: &Path,
40-
data: &Path, status: &mut StatusBackend
41+
data: &Path, only_cached: bool, status: &mut StatusBackend
4142
) -> Result<LocalCache<B>> {
4243
// If the `digest` file exists, we assume that it is valid; this is
4344
// *essential* so that we can use a URL as our default IoProvider
@@ -142,7 +143,8 @@ impl<B: Bundle> LocalCache<B> {
142143
checked_digest: checked_digest,
143144
manifest_path: manifest_path,
144145
data_path: data.to_owned(),
145-
contents: contents
146+
contents: contents,
147+
only_cached: only_cached,
146148
})
147149
}
148150

@@ -225,6 +227,11 @@ impl<B: Bundle> LocalCache<B> {
225227
};
226228
}
227229

230+
// The file is not in the cache and we are asked not to try to fetch it.
231+
if self.only_cached {
232+
return OpenResult::NotAvailable;
233+
}
234+
228235
// Bummer, we haven't seen this file before. We need to (try to) fetch
229236
// the item from the backend, saving it to disk and calculating its
230237
// digest ourselves, then enter it in the cache and in our manifest.

0 commit comments

Comments
 (0)