Skip to content

Commit c7e1400

Browse files
committed
try close_file crate and see tests fail for some reason (#301)
1 parent 3f28e20 commit c7e1400

File tree

4 files changed

+69
-29
lines changed

4 files changed

+69
-29
lines changed

Cargo.lock

Lines changed: 60 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-worktree/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ thiserror = "1.0.26"
4040
bstr = { version = "0.2.13", default-features = false }
4141

4242
document-features = { version = "0.2.0", optional = true }
43+
close-file = "0.1.0"
4344

4445
[target.'cfg(unix)'.dependencies]
4546
libc = "0.2.119"

git-worktree/src/index/checkout.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ pub enum Error<E: std::error::Error + Send + Sync + 'static> {
219219
Time(#[from] std::time::SystemTimeError),
220220
#[error("IO error while writing blob or reading file metadata or changing filetype")]
221221
Io(#[from] std::io::Error),
222+
#[error(transparent)]
223+
FileClose(#[from] close_file::CloseError),
222224
#[error("object {} for checkout at {} could not be retrieved from object database", .oid.to_hex(), .path.display())]
223225
Find {
224226
#[source]

git-worktree/src/index/entry.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::path::Path;
22
use std::{convert::TryInto, fs::OpenOptions, io::Write, time::Duration};
33

44
use bstr::BStr;
5+
use close_file::Closable;
56
use git_hash::oid;
67
use git_index::Entry;
78

@@ -69,6 +70,7 @@ where
6970
// NOTE: we don't call `file.sync_all()` here knowing that some filesystems don't handle this well.
7071
// revisit this once there is a bug to fix.
7172
update_fstat(entry, file.metadata()?)?;
73+
// file.close()?;
7274
obj.data.len()
7375
}
7476
git_index::entry::Mode::SYMLINK => {
@@ -85,10 +87,11 @@ where
8587
crate::os::create_symlink(symlink_destination, p)
8688
})?;
8789
} else {
88-
try_write_or_unlink(dest, overwrite_existing, |p| {
90+
let mut file = try_write_or_unlink(dest, overwrite_existing, |p| {
8991
open_options(p, destination_is_initially_empty, overwrite_existing).open(&dest)
90-
})?
91-
.write_all(obj.data)?;
92+
})?;
93+
file.write_all(obj.data)?;
94+
file.close()?;
9295
}
9396

9497
update_fstat(entry, std::fs::symlink_metadata(&dest)?)?;

0 commit comments

Comments
 (0)