Skip to content

Commit

Permalink
fix: don't overwrite unexpanded git-lfs pointer files. (#607)
Browse files Browse the repository at this point in the history
It's possible for those with incomplete `git-lfs` installations
(and many more situations) to end up in a spot where pointer files
aren't expanded. If we overwrite the with archives, files look
changed which can be confusing and lead to even bigger messes
to happen.

Now we don't overwrite those files anyomre.
  • Loading branch information
Byron committed Nov 21, 2022
1 parent 519db50 commit 761b7d7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/tools/src/lib.rs
Expand Up @@ -417,6 +417,16 @@ fn write_failure_marker(failure_marker: &Path) {
std::fs::write(failure_marker, []).ok();
}

fn is_lfs_pointer_file(path: &Path) -> bool {
const PREFIX: &[u8] = b"version https://git-lfs";
let mut buf = [0_u8; PREFIX.len()];
std::fs::OpenOptions::new()
.read(true)
.open(path)
.and_then(|mut f| f.read_exact(&mut buf))
.map_or(false, |_| buf.starts_with(PREFIX))
}

/// The `script_identity` will be baked into the soon to be created `archive` as it identitifies the script
/// that created the contents of `source_dir`.
fn create_archive_if_not_on_ci(source_dir: &Path, archive: &Path, script_identity: u32) -> std::io::Result<()> {
Expand All @@ -426,6 +436,13 @@ fn create_archive_if_not_on_ci(source_dir: &Path, archive: &Path, script_identit
if is_excluded(archive) {
return Ok(());
}
if is_lfs_pointer_file(archive) {
eprintln!(
"Refusing to overwrite `git-lfs` pointer file at \"{}\" - git lfs might not be properly installed.",
archive.display()
);
return Ok(());
}
std::fs::create_dir_all(archive.parent().expect("archive is a file"))?;

let meta_dir = populate_meta_dir(source_dir, script_identity)?;
Expand Down

0 comments on commit 761b7d7

Please sign in to comment.