diff --git a/src/docbuilder/queue.rs b/src/docbuilder/queue.rs index dd161c5f8..54cfc936a 100644 --- a/src/docbuilder/queue.rs +++ b/src/docbuilder/queue.rs @@ -12,7 +12,8 @@ impl DocBuilder { /// Returns the number of crates added pub fn get_new_crates(&mut self) -> Result { let conn = connect_db()?; - let (mut changes, oid) = self.index.diff().peek_changes()?; + let diff = self.index.diff()?; + let (mut changes, oid) = diff.peek_changes()?; let mut crates_added = 0; // I believe this will fix ordering of queue if we get more than one crate from changes @@ -58,7 +59,7 @@ impl DocBuilder { } } - self.index.diff().set_last_seen_reference(oid)?; + diff.set_last_seen_reference(oid)?; Ok(crates_added) } diff --git a/src/index/mod.rs b/src/index/mod.rs index 87359b0c4..0953f3668 100644 --- a/src/index/mod.rs +++ b/src/index/mod.rs @@ -4,11 +4,11 @@ use url::Url; use self::api::Api; use crate::error::Result; +use failure::ResultExt; pub(crate) mod api; pub(crate) struct Index { - diff: crates_index_diff::Index, path: PathBuf, api: Api, } @@ -41,14 +41,19 @@ fn load_config(repo: &git2::Repository) -> Result { impl Index { pub(crate) fn new(path: impl AsRef) -> Result { let path = path.as_ref().to_owned(); - let diff = crates_index_diff::Index::from_path_or_cloned(&path)?; - let config = load_config(diff.repository())?; - let api = Api::new(config.api)?; - Ok(Self { diff, path, api }) + // This initializes the repository, then closes it afterwards to avoid leaking file descriptors. + // See https://github.com/rust-lang/docs.rs/pull/847 + let diff = crates_index_diff::Index::from_path_or_cloned(&path) + .context("initialising registry index repository")?; + let config = load_config(diff.repository()).context("loading registry config")?; + let api = Api::new(config.api).context("initialising registry api client")?; + Ok(Self { path, api }) } - pub(crate) fn diff(&self) -> &crates_index_diff::Index { - &self.diff + pub(crate) fn diff(&self) -> Result { + let diff = crates_index_diff::Index::from_path_or_cloned(&self.path) + .context("re-opening registry index for diff")?; + Ok(diff) } pub(crate) fn api(&self) -> &Api {