Skip to content

Commit 74a547a

Browse files
committed
fix: assure duplicate packs and indices aren't overwriting existing ones (#1404).
That way, on Windows there is no chance for access-denied errors. Maybe there are other advantages as well even for Unix. Since packs are usually written rarely, in comparison to loose objects, the extra file accesss seems acceptable.
1 parent ecfde07 commit 74a547a

File tree

1 file changed

+24
-15
lines changed
  • gix-pack/src/bundle/write

1 file changed

+24
-15
lines changed

gix-pack/src/bundle/write/mod.rs

+24-15
Original file line numberDiff line numberDiff line change
@@ -310,26 +310,35 @@ impl crate::Bundle {
310310
} else {
311311
let data_path = directory.join(format!("pack-{}.pack", outcome.data_hash.to_hex()));
312312
let index_path = data_path.with_extension("idx");
313-
let keep_path = data_path.with_extension("keep");
313+
let keep_path = if data_path.is_file() {
314+
// avoid trying to overwrite existing files, we know they have the same content
315+
// and this is likely to fail on Windows as negotiation opened the pack.
316+
None
317+
} else {
318+
let keep_path = data_path.with_extension("keep");
314319

315-
std::fs::write(&keep_path, b"")?;
316-
Arc::try_unwrap(data_file)
317-
.expect("only one handle left after pack was consumed")
318-
.into_inner()
319-
.into_inner()
320-
.map_err(|err| Error::from(err.into_error()))?
321-
.persist(&data_path)?;
322-
index_file
323-
.persist(&index_path)
324-
.map_err(|err| {
325-
gix_features::trace::warn!("pack file at \"{}\" is retained despite failing to move the index file into place. You can use plumbing to make it usable.",data_path.display());
326-
err
327-
})?;
320+
std::fs::write(&keep_path, b"")?;
321+
Arc::try_unwrap(data_file)
322+
.expect("only one handle left after pack was consumed")
323+
.into_inner()
324+
.into_inner()
325+
.map_err(|err| Error::from(err.into_error()))?
326+
.persist(&data_path)?;
327+
Some(keep_path)
328+
};
329+
if !index_path.is_file() {
330+
index_file
331+
.persist(&index_path)
332+
.map_err(|err| {
333+
gix_features::trace::warn!("pack file at \"{}\" is retained despite failing to move the index file into place. You can use plumbing to make it usable.",data_path.display());
334+
err
335+
})?;
336+
}
328337
WriteOutcome {
329338
outcome,
330339
data_path: Some(data_path),
331340
index_path: Some(index_path),
332-
keep_path: Some(keep_path),
341+
keep_path,
333342
}
334343
}
335344
}

0 commit comments

Comments
 (0)