diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index 329538663ae..21d68c1cef4 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -732,5 +732,6 @@ pub fn set_config(cfg: &Config, let contents = toml::Value::Table(toml).to_string(); try!(file.seek(SeekFrom::Start(0))); try!(file.write_all(contents.as_bytes())); + try!(file.file().set_len(contents.len() as u64)); Ok(()) } diff --git a/tests/registry.rs b/tests/registry.rs index 0ddb55999d5..1a069f5628c 100644 --- a/tests/registry.rs +++ b/tests/registry.rs @@ -580,6 +580,19 @@ fn login_with_no_cargo_dir() { execs().with_status(0)); } +#[test] +fn login_with_differently_sized_token() { + // Verify that the configuration file gets properly trunchated. + let home = paths::home().join("new-home"); + t!(fs::create_dir(&home)); + assert_that(cargo_process().arg("login").arg("lmaolmaolmao").arg("-v"), + execs().with_status(0)); + assert_that(cargo_process().arg("login").arg("lmao").arg("-v"), + execs().with_status(0)); + assert_that(cargo_process().arg("login").arg("lmaolmaolmao").arg("-v"), + execs().with_status(0)); +} + #[test] fn bad_license_file() { Package::new("foo", "1.0.0").publish();