pub fn remove_bins(&self, query: &Spec, bins: &[&str]) -> Res<u32> {
        fn contains(sum: &str, query: &Spec) -> bool {
            match (
                &query.name,
                query.resolution.as_ref(),
                query.version.as_ref(),
            ) {
                (_, Some(_), Some(_)) => sum == query.to_string(),
                (name, None, Some(ver)) => {
                    sum.starts_with(&name.to_string()) && sum.ends_with(&ver.to_string())
                }
                _ => sum.starts_with(&query.to_string()),
            }
        };

        let mut c = 0;
        if self.layout.bin.join(".bins").exists() {
            let mut s = String::new();
            let mut f = fs::OpenOptions::new()
                .read(true)
                .open(self.layout.bin.join(".bins"))
                .with_context(|e| format_err!("could not open .bins file:\n{}", e))?;

            f.read_to_string(&mut s)
                .with_context(|e| format_err!("could not read from .bins file:\n{}", e))?;

            let dot: IndexMap<String, String> = toml::from_str(&s)
                .with_context(|e| format_err!("could not deserialize .bins file:\n{}", e))?;

            let (discard, dot): (IndexMap<_, _>, IndexMap<_, _>) =
                dot.into_iter().partition(|(bin, sum)| {
                    (bins.is_empty() || bins.contains(&bin.as_str())) && contains(sum, query)
                });

            for (bin, _) in discard {
                fs::remove_file(self.layout.bin.join(&bin))
                    .with_context(|e| format_err!("couldn't remove binary {}:\n{}", bin, e))?;
                c += 1;
            }

            drop(f);
            fs::remove_file(self.layout.bin.join(".bins"))
                .with_context(|e| format_err!("could not clear existing .bins file:\n{}", e))?;

            fs::write(
                self.layout.bin.join(".bins"),
                toml::to_string(&dot).unwrap().as_bytes(),
            ).with_context(|e| format_err!("could not write to .bins file:\n{}", e))?;
        }

        Ok(c)
    }
// If bins is empty, it's assumed to mean "delete all binaries"
If bins is empty, it's assumed to mean "delete all binaries"
If bins is empty it ' s assumed to mean " delete all binaries "
pub fn remove_bins(&self, query: &Spec, bins: &[&str]) -> Res<u32> {
        fn contains(sum: &str, query: &Spec) -> bool {
            match (
                &query.name,
                query.resolution.as_ref(),
                query.version.as_ref(),
            ) {
                (_, Some(_), Some(_)) => sum == query.to_string(),
                (name, None, Some(ver)) => {
                    sum.starts_with(&name.to_string()) && sum.ends_with(&ver.to_string())
                }
                _ => sum.starts_with(&query.to_string()),
            }
        };
        let mut c = 0;
        if self.layout.bin.join(".bins").exists() {
            let mut s = String::new();
            let mut f = fs::OpenOptions::new()
                .read(true)
                .open(self.layout.bin.join(".bins"))
                .with_context(|e| format_err!("could not open .bins file:\n{}", e))?;
            f.read_to_string(&mut s)
                .with_context(|e| format_err!("could not read from .bins file:\n{}", e))?;
            let dot: IndexMap<String, String> = toml::from_str(&s)
                .with_context(|e| format_err!("could not deserialize .bins file:\n{}", e))?;
            let (discard, dot): (IndexMap<_, _>, IndexMap<_, _>) =
                dot.into_iter().partition(|(bin, sum)| {
                    (bins.is_empty() || bins.contains(&bin.as_str())) && contains(sum, query)
                });
            for (bin, _) in discard {
                fs::remove_file(self.layout.bin.join(&bin))
                    .with_context(|e| format_err!("couldn't remove binary {}:\n{}", bin, e))?;
                c += 1;
            }
            drop(f);
            fs::remove_file(self.layout.bin.join(".bins"))
                .with_context(|e| format_err!("could not clear existing .bins file:\n{}", e))?;
            fs::write(
                self.layout.bin.join(".bins"),
                toml::to_string(&dot).unwrap().as_bytes(),
            ).with_context(|e| format_err!("could not write to .bins file:\n{}", e))?;
        }
        Ok(c)
    }
pub fn remove_bins ( & self , query : & Spec , bins : & [ & str ] ) -> Res < u32 > { fn contains ( sum : & str , query : & Spec ) -> bool { match ( & query . name , query . resolution . as_ref ( ) , query . version . as_ref ( ) , ) { ( _ , Some ( _ ) , Some ( _ ) ) => sum == query . to_string ( ) , ( name , None , Some ( ver ) ) => { sum . starts_with ( & name . to_string ( ) ) && sum . ends_with ( & ver . to_string ( ) ) } _ => sum . starts_with ( & query . to_string ( ) ) , } } ; let mut c = 0 ; if self . layout . bin . join ( " " ) . exists ( ) { let mut s = String :: new ( ) ; let mut f = fs :: OpenOptions :: new ( ) . read ( true ) . open ( self . layout . bin . join ( " " ) ) . with_context ( | e | format_err ! ( " \n " e ) ) ? ; f . read_to_string ( & mut s ) . with_context ( | e | format_err ! ( " \n " e ) ) ? ; let dot : IndexMap < String , String > = toml :: from_str ( & s ) . with_context ( | e | format_err ! ( " \n " e ) ) ? ; let ( discard , dot ) : ( IndexMap < _ , _ > , IndexMap < _ , _ > ) = dot . into_iter ( ) . partition ( | ( bin , sum ) | { ( bins . is_empty ( ) || bins . contains ( & bin . as_str ( ) ) ) && contains ( sum , query ) } ) ; for ( bin , _ ) in discard { fs :: remove_file ( self . layout . bin . join ( & bin ) ) . with_context ( | e | format_err ! ( " \n " bin e ) ) ? ; c += 1 ; } drop ( f ) ; fs :: remove_file ( self . layout . bin . join ( " " ) ) . with_context ( | e | format_err ! ( " \n " e ) ) ? ; fs :: write ( self . layout . bin . join ( " " ) , toml :: to_string ( & dot ) . unwrap ( ) . as_bytes ( ) , ) . with_context ( | e | format_err ! ( " \n " e ) ) ? ; } Ok ( c ) }
If bins is empty, it's assumed to mean "delete all binaries"
If bins is empty it ' s assumed to mean " delete all binaries "
&self
query
&Spec
bins
&[&str]