local_working_copy: take owned Read in write_file()

It doesn't make sense to use the `Read` instance after calling
`write_file()`, so the caller shouldn't need to hold on to the
instance.

This slightly simplifies a later patch replacing `Read` by
`AsyncRead`.
This commit is contained in:
Martin von Zweigbergk 2025-05-17 11:08:06 -07:00
parent 3611796098
commit 4f0e84f6cb

View file

@ -1612,7 +1612,7 @@ impl TreeState {
fn write_file(
&self,
disk_path: &Path,
contents: &mut dyn Read,
mut contents: impl Read,
executable: bool,
) -> Result<FileState, CheckoutError> {
let mut file = OpenOptions::new()
@ -1623,7 +1623,7 @@ impl TreeState {
message: format!("Failed to open file {} for writing", disk_path.display()),
err: err.into(),
})?;
let size = io::copy(contents, &mut file).map_err(|err| CheckoutError::Other {
let size = io::copy(&mut contents, &mut file).map_err(|err| CheckoutError::Other {
message: format!("Failed to write file {}", disk_path.display()),
err: err.into(),
})?;
@ -1851,8 +1851,8 @@ impl TreeState {
deleted_files.insert(path);
continue;
}
MaterializedTreeValue::File(mut file) => {
self.write_file(&disk_path, &mut file.reader, file.executable)?
MaterializedTreeValue::File(file) => {
self.write_file(&disk_path, file.reader, file.executable)?
}
MaterializedTreeValue::Symlink { id: _, target } => {
if self.symlink_support {