Skip to content

Commit 0581c26

Browse files
committed
Drop use of FileExt
I stumbled across the fact that we no longer need coreos/openat-ext@c377a54 because rust-lang/rust#75272 landed just a few months after! While we're here, slightly clean up the fd dance to make things a bit safer using `BorrowedFd`. It's interesting to note here that with io-lifetimes we could add a method to the glib crate to borrow the underlying fd safely.
1 parent 9645cee commit 0581c26

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ futures-util = "0.3.13"
2323
gvariant = "0.4.0"
2424
hex = "0.4.3"
2525
indicatif = "0.16.0"
26+
io-lifetimes = "0.4"
2627
once_cell = "1.9"
2728
libc = "0.2.92"
2829
oci-spec = "0.5.4"

lib/src/ima.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@
44

55
use crate::objgv::*;
66
use anyhow::{Context, Result};
7+
use cap_std_ext::rustix::fd::BorrowedFd;
78
use fn_error_context::context;
89
use gio::glib;
910
use gio::prelude::*;
1011
use glib::Cast;
1112
use glib::Variant;
1213
use gvariant::aligned_bytes::TryAsAligned;
1314
use gvariant::{gv, Marker, Structure};
14-
use openat_ext::FileExt;
15+
use io_lifetimes::AsFilelike;
1516
use ostree::gio;
1617
use std::collections::{BTreeMap, HashMap};
1718
use std::ffi::CString;
1819
use std::fs::File;
20+
use std::ops::DerefMut;
1921
use std::os::unix::io::AsRawFd;
20-
use std::os::unix::prelude::{FromRawFd, IntoRawFd};
2122
use std::process::{Command, Stdio};
2223
use std::rc::Rc;
2324
use std::{convert::TryInto, io::Seek};
@@ -122,10 +123,9 @@ impl<'a> CommitRewriter<'a> {
122123
// If we're operating on a bare repo, we can clone the file (copy_file_range) directly.
123124
if let Ok(instream) = instream.clone().downcast::<gio::UnixInputStream>() {
124125
// 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())?;
129129
} else {
130130
// If we're operating on an archive repo, then we need to uncompress
131131
// and recompress...

0 commit comments

Comments
 (0)