mirror of
https://github.com/facebook/sapling.git
synced 2024-10-06 23:07:18 +03:00
prefetch-profile: don't fail if profile is already active
Summary: `eden prefetch-profile activate` currently fails if the prefetch profile we're trying to activate is already active. I don't really consider this a failure, as the intended profile is already activated. Instead of returning an error, we should just return early. Reviewed By: genevievehelsel Differential Revision: D43377801 fbshipit-source-id: 59c34ada539dd0b0789ec48f3a2ed2d7e66558cb
This commit is contained in:
parent
b02b56cd97
commit
0942f1b5f5
@ -319,24 +319,22 @@ impl CheckoutConfig {
|
||||
}
|
||||
|
||||
/// Add a profile to the config (read the config file and write it back
|
||||
/// with profile added).
|
||||
/// with profile added). Returns true if we should fetch, false otherwise.
|
||||
pub fn activate_profile(
|
||||
&mut self,
|
||||
profile: &str,
|
||||
config_dir: PathBuf,
|
||||
force_fetch: &bool,
|
||||
) -> Result<()> {
|
||||
) -> Result<bool> {
|
||||
if let Some(profiles) = &mut self.profiles {
|
||||
if profiles.active.iter().any(|x| x == profile) {
|
||||
// The profile is already activated so we don't need to update the profile list,
|
||||
// but we want to return a success so we continue with the fetch
|
||||
if *force_fetch {
|
||||
return Ok(());
|
||||
return Ok(true);
|
||||
}
|
||||
return Err(EdenFsError::Other(anyhow!(
|
||||
"{} is already an active prefetch profile",
|
||||
profile
|
||||
)));
|
||||
eprintln!("{} is already an active prefetch profile", profile);
|
||||
return Ok(false);
|
||||
}
|
||||
profiles.push(profile);
|
||||
self.save_config(config_dir.clone()).with_context(|| {
|
||||
@ -346,7 +344,7 @@ impl CheckoutConfig {
|
||||
)
|
||||
})?;
|
||||
}
|
||||
Ok(())
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// Switch on predictive prefetch profiles (read the config file and write
|
||||
|
@ -288,16 +288,23 @@ impl PrefetchCmd {
|
||||
let checkout_config = CheckoutConfig::parse_config(config_dir.clone());
|
||||
let result = checkout_config
|
||||
.and_then(|mut config| config.activate_profile(profile_name, config_dir, force_fetch));
|
||||
if let Err(e) = result {
|
||||
#[cfg(fbcode_build)]
|
||||
{
|
||||
sample.fail(&e.to_string());
|
||||
match result {
|
||||
Ok(res) => {
|
||||
#[cfg(fbcode_build)]
|
||||
send(sample.builder);
|
||||
if !res {
|
||||
return Ok(0);
|
||||
}
|
||||
}
|
||||
return Err(anyhow::Error::new(e));
|
||||
}
|
||||
#[cfg(fbcode_build)]
|
||||
send(sample.builder);
|
||||
Err(e) => {
|
||||
#[cfg(fbcode_build)]
|
||||
{
|
||||
sample.fail(&e.to_string());
|
||||
send(sample.builder);
|
||||
}
|
||||
return Err(anyhow::Error::new(e));
|
||||
}
|
||||
};
|
||||
|
||||
let checkout = find_checkout(instance, &options.checkout).with_context(|| {
|
||||
anyhow!(
|
||||
|
Loading…
Reference in New Issue
Block a user