add boolean to struct to support what crates is sending
authorNatalie Boehm <nmb56@pitt.edu>
Thu, 28 Sep 2017 19:23:48 +0000 (15:23 -0400)
committerNatalie Boehm <nmb56@pitt.edu>
Thu, 28 Sep 2017 19:23:54 +0000 (15:23 -0400)
in case an old version of cargo is being used. the old
version should be able to decode the boolean and ignore
the string.

src/cargo/ops/registry.rs
src/crates-io/lib.rs

index 72c41405bca46a466b46081c67731be625b29eba..42ff2f872076205f06e18edbc5d054265d20145b 100644 (file)
@@ -320,8 +320,6 @@ pub fn modify_owners(config: &Config, opts: &OwnersOptions) -> CargoResult<()> {
 
     if let Some(ref v) = opts.to_add {
         let v = v.iter().map(|s| &s[..]).collect::<Vec<_>>();
-        //config.shell().status("Owner", format!("adding {:?} to crate {}",
-        //                                            v, name))?;
         let msg = registry.add_owners(&name, &v).map_err(|e| {
             CargoError::from(format!("failed to invite owners to crate {}: {}", name, e))
         })?;
index c2a8458600fea7d645188cd160ed559d979a40e5..6caa46cf716fea830130b18a1f2023eec8f4ec38 100644 (file)
@@ -116,7 +116,7 @@ pub struct Warnings {
 }
 
 #[derive(Deserialize)] struct R { ok: bool }
-#[derive(Deserialize)] struct OwnerResponse { ok: String }
+#[derive(Deserialize)] struct OwnerResponse { ok: bool, msg: String }
 #[derive(Deserialize)] struct ApiErrorList { errors: Vec<ApiError> }
 #[derive(Deserialize)] struct ApiError { detail: String }
 #[derive(Serialize)] struct OwnersReq<'a> { users: &'a [&'a str] }
@@ -142,14 +142,15 @@ impl Registry {
         let body = serde_json::to_string(&OwnersReq { users: owners })?;
         let body = self.put(format!("/crates/{}/owners", krate),
                                  body.as_bytes())?;
-        Ok(serde_json::from_str::<OwnerResponse>(&body)?.ok)
+        assert!(serde_json::from_str::<OwnerResponse>(&body)?.ok);
+        Ok(serde_json::from_str::<OwnerResponse>(&body)?.msg)
     }
 
     pub fn remove_owners(&mut self, krate: &str, owners: &[&str]) -> Result<()> {
         let body = serde_json::to_string(&OwnersReq { users: owners })?;
         let body = self.delete(format!("/crates/{}/owners", krate),
                                     Some(body.as_bytes()))?;
-        serde_json::from_str::<OwnerResponse>(&body)?;
+        assert!(serde_json::from_str::<OwnerResponse>(&body)?.ok);
         Ok(())
     }