|
4 | 4 |
|
5 | 5 | use crate::objgv::*;
|
6 | 6 | use anyhow::{Context, Result};
|
| 7 | +use cap_std_ext::rustix::fd::BorrowedFd; |
7 | 8 | use fn_error_context::context;
|
8 | 9 | use gio::glib;
|
9 | 10 | use gio::prelude::*;
|
10 | 11 | use glib::Cast;
|
11 | 12 | use glib::Variant;
|
12 | 13 | use gvariant::aligned_bytes::TryAsAligned;
|
13 | 14 | use gvariant::{gv, Marker, Structure};
|
14 |
| -use openat_ext::FileExt; |
| 15 | +use io_lifetimes::AsFilelike; |
15 | 16 | use ostree::gio;
|
16 | 17 | use std::collections::{BTreeMap, HashMap};
|
17 | 18 | use std::ffi::CString;
|
18 | 19 | use std::fs::File;
|
| 20 | +use std::ops::DerefMut; |
19 | 21 | use std::os::unix::io::AsRawFd;
|
20 |
| -use std::os::unix::prelude::{FromRawFd, IntoRawFd}; |
21 | 22 | use std::process::{Command, Stdio};
|
22 | 23 | use std::rc::Rc;
|
23 | 24 | use std::{convert::TryInto, io::Seek};
|
@@ -122,10 +123,9 @@ impl<'a> CommitRewriter<'a> {
|
122 | 123 | // If we're operating on a bare repo, we can clone the file (copy_file_range) directly.
|
123 | 124 | if let Ok(instream) = instream.clone().downcast::<gio::UnixInputStream>() {
|
124 | 125 | // View the fd as a File
|
125 |
| - let instream_fd = unsafe { File::from_raw_fd(instream.as_raw_fd()) }; |
126 |
| - instream_fd.copy_to(tempf.as_file_mut())?; |
127 |
| - // Leak to avoid double close |
128 |
| - let _ = instream_fd.into_raw_fd(); |
| 126 | + let instream_fd = unsafe { BorrowedFd::borrow_raw_fd(instream.as_raw_fd()) }; |
| 127 | + let instream_fd = &mut instream_fd.as_filelike_view::<File>(); |
| 128 | + std::io::copy(instream_fd.deref_mut(), tempf.as_file_mut())?; |
129 | 129 | } else {
|
130 | 130 | // If we're operating on an archive repo, then we need to uncompress
|
131 | 131 | // and recompress...
|
|
0 commit comments