Skip to content

Commit 626576b

Browse files
committed
provide some more information when using archives; debug windows more (#384)
1 parent 4ed1185 commit 626576b

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
with:
4848
command: check
4949
args: --all --bins --tests --examples
50-
- run: git lfs fetch && git lfs checkout
50+
- run: git lfs fetch && git lfs checkout && cargo test --package git-ref -- nocapture
5151
- name: "Test (crossterm)"
5252
uses: actions-rs/cargo@v1
5353
with:

tests/tools/src/lib.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,14 @@ pub fn scripted_fixture_repo_read_only_with_args(
127127
if !script_result_directory.is_dir() {
128128
std::fs::create_dir_all(&script_result_directory)?;
129129
match extract_archive(&archive_file_path, &script_result_directory, script_identity) {
130-
Ok(_) => {}
130+
Ok((archive_id, platform)) => {
131+
eprintln!(
132+
"Extracted fixture from archive '{}' ({}, {:?})",
133+
archive_file_path.display(),
134+
archive_id,
135+
platform
136+
)
137+
}
131138
Err(err) => {
132139
if err.kind() != std::io::ErrorKind::NotFound {
133140
eprintln!("{}", err);
@@ -201,7 +208,10 @@ const META_GIT_VERSION: &str = "git-version";
201208
fn populate_meta_dir(destination_dir: &Path, script_identity: u32) -> std::io::Result<PathBuf> {
202209
let meta_dir = destination_dir.join(META_DIR_NAME);
203210
std::fs::create_dir_all(&meta_dir)?;
204-
std::fs::write(meta_dir.join(META_IDENTITY), format!("{}", script_identity).as_bytes())?;
211+
std::fs::write(
212+
meta_dir.join(META_IDENTITY),
213+
format!("{}-{}", script_identity, if cfg!(windows) { "windows" } else { "unix" }).as_bytes(),
214+
)?;
205215
std::fs::write(
206216
meta_dir.join(META_GIT_VERSION),
207217
&std::process::Command::new("git").arg("--version").output()?.stdout,
@@ -211,21 +221,29 @@ fn populate_meta_dir(destination_dir: &Path, script_identity: u32) -> std::io::R
211221

212222
/// `required_script_identity` is the identity of the script that generated the state that is contained in `archive`.
213223
/// If this is not the case, the arvhive will be ignored.
214-
fn extract_archive(archive: &Path, destination_dir: &Path, required_script_identity: u32) -> std::io::Result<()> {
224+
fn extract_archive(
225+
archive: &Path,
226+
destination_dir: &Path,
227+
required_script_identity: u32,
228+
) -> std::io::Result<(u32, Option<String>)> {
215229
let mut archive_buf = Vec::<u8>::new();
216230
let mut decoder = xz2::bufread::XzDecoder::new(std::io::BufReader::new(std::fs::File::open(archive)?));
217231
std::io::copy(&mut decoder, &mut archive_buf)?;
218232

219233
let mut entry_buf = Vec::<u8>::new();
220-
let archive_identity: u32 = tar::Archive::new(std::io::Cursor::new(&mut &*archive_buf))
234+
let (archive_identity, platform): (u32, _) = tar::Archive::new(std::io::Cursor::new(&mut &*archive_buf))
221235
.entries_with_seek()?
222236
.filter_map(|e| e.ok())
223237
.find_map(|mut e: tar::Entry<'_, _>| {
224238
let path = e.path().ok()?;
225239
if path.parent()?.file_name()? == META_DIR_NAME && path.file_name()? == META_IDENTITY {
226240
entry_buf.clear();
227241
e.read_to_end(&mut entry_buf).ok()?;
228-
entry_buf.to_str().ok()?.trim().parse().ok()
242+
let mut tokens = entry_buf.to_str().ok()?.trim().splitn(2, '-');
243+
match (tokens.next(), tokens.next()) {
244+
(Some(id), platform) => Some((id.parse().ok()?, platform.map(ToOwned::to_owned))),
245+
_ => None,
246+
}
229247
} else {
230248
None
231249
}
@@ -248,7 +266,7 @@ fn extract_archive(archive: &Path, destination_dir: &Path, required_script_ident
248266
}
249267
entry.unpack_in(&destination_dir)?;
250268
}
251-
Ok(())
269+
Ok((archive_identity, platform))
252270
}
253271

254272
pub fn to_bstr_err(err: nom::Err<VerboseError<&[u8]>>) -> VerboseError<&BStr> {

0 commit comments

Comments
 (0)