+
+ fn update_index_worker(&mut self) -> CargoResult<()> {
+ if self.config.offline() {
+ return Ok(());
+ }
+ if self.config.cli_unstable().no_index_update {
+ return Ok(());
+ }
+ // Make sure the index is only updated once per session since it is an
+ // expensive operation. This generally only happens when the resolver
+ // is run multiple times, such as during `cargo publish`.
+ if self.config.updated_sources().contains(&self.source_id) {
+ return Ok(());
+ }
+
+ debug!("updating the index");
+
+ // Ensure that we'll actually be able to acquire an HTTP handle later on
+ // once we start trying to download crates. This will weed out any
+ // problems with `.cargo/config` configuration related to HTTP.
+ //
+ // This way if there's a problem the error gets printed before we even
+ // hit the index, which may not actually read this configuration.
+ self.config.http()?;
+
+ self.prepare()?;
+ self.head.set(None);
+ *self.tree.borrow_mut() = None;
+ self.current_sha.set(None);
+ let path = self.config.assert_package_cache_locked(&self.index_path);
+ self.config
+ .shell()
+ .status("Updating", self.source_id.display_index())?;
+
+ // Fetch the latest version of our `index_git_ref` into the index
+ // checkout.
+ let url = self.source_id.url();
+ let repo = self.repo.borrow_mut().unwrap();
+ git::fetch(repo, url.as_str(), &self.index_git_ref, self.config)
+ .with_context(|| format!("failed to fetch `{}`", url))?;
+ self.config.updated_sources().insert(self.source_id);
+
+ // Create a dummy file to record the mtime for when we updated the
+ // index.
+ paths::create(&path.join(LAST_UPDATED_FILE))?;
+
+ Ok(())
+ }