Skip to content

Commit d64c168

Browse files
committed
Simplify json production and append to archive
Per github review.
1 parent ab78772 commit d64c168

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/cargo/ops/cargo_package.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::fs::{self, File};
2-
use std::io::{Cursor, SeekFrom, Write};
32
use std::io::prelude::*;
3+
use std::io::SeekFrom;
44
use std::path::{self, Path, PathBuf};
55
use std::sync::Arc;
66

@@ -370,16 +370,14 @@ fn tar(
370370
header.set_path(&path).chain_err(|| {
371371
format!("failed to add to archive: `{}`", fnd)
372372
})?;
373-
let mut buff = Cursor::new(Vec::with_capacity(256));
374-
writeln!(buff, "{}", serde_json::to_string_pretty(json)?)?;
373+
let json = format!("{}\n", serde_json::to_string_pretty(json)?);
375374
let mut header = Header::new_ustar();
376375
header.set_path(&path)?;
377376
header.set_entry_type(EntryType::file());
378377
header.set_mode(0o644);
379-
header.set_size(buff.position() as u64);
378+
header.set_size(json.len() as u64);
380379
header.set_cksum();
381-
buff.seek(SeekFrom::Start(0))?;
382-
ar.append(&header, &mut buff).chain_err(|| {
380+
ar.append(&header, json.as_bytes()).chain_err(|| {
383381
internal(format!("could not archive source file `{}`", fnd))
384382
})?;
385383
}

0 commit comments

Comments
 (0)