Skip to content

Commit 9923542

Browse files
committed
Merge branch 'fix-1404'
2 parents ecfde07 + 303724c commit 9923542

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
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
}

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,20 @@ impl Default for Options {
3333
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
3434
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3535
pub struct Outcome {
36-
/// The successful result of the index write operation
36+
/// The successful result of the index write operation.
3737
pub index: crate::index::write::Outcome,
38-
/// The version of the pack
38+
/// The version of the pack.
3939
pub pack_version: crate::data::Version,
40-
/// The kind of hash stored within the pack and indices
40+
/// The kind of hash stored within the pack and indices.
4141
pub object_hash: gix_hash::Kind,
4242

43-
/// The path to the pack index file
43+
/// The path to the pack index file.
4444
pub index_path: Option<PathBuf>,
45-
/// The path to the pack data file
45+
/// The path to the pack data file.
4646
pub data_path: Option<PathBuf>,
4747
/// The path to the `.keep` file to prevent collection of the newly written pack until refs are pointing to it.
48+
/// It might be `None` if the file at `data_path` already existed, indicating that we have received a pack that
49+
/// was already present locally.
4850
///
4951
/// The file is created right before moving the pack data and index data into place (i.e. `data_path` and `index_path`)
5052
/// and is expected to be removed by the caller when ready.

tests/snapshots/plumbing/no-repo/pack/index/create/output-dir-restore-as-json-success

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@
5555
"object_hash": "Sha1",
5656
"index_path": ""
5757
"data_path": ""
58-
"keep_path": ""
58+
"keep_path": null
5959
}

0 commit comments

Comments
 (0)