Skip to content

Commit

Permalink
Drop use of FileExt
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cgwalters committed Jan 26, 2022
1 parent 9645cee commit 0581c26
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ futures-util = "0.3.13"
gvariant = "0.4.0"
hex = "0.4.3"
indicatif = "0.16.0"
io-lifetimes = "0.4"
once_cell = "1.9"
libc = "0.2.92"
oci-spec = "0.5.4"
Expand Down
12 changes: 6 additions & 6 deletions lib/src/ima.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@

use crate::objgv::*;
use anyhow::{Context, Result};
use cap_std_ext::rustix::fd::BorrowedFd;
use fn_error_context::context;
use gio::glib;
use gio::prelude::*;
use glib::Cast;
use glib::Variant;
use gvariant::aligned_bytes::TryAsAligned;
use gvariant::{gv, Marker, Structure};
use openat_ext::FileExt;
use io_lifetimes::AsFilelike;
use ostree::gio;
use std::collections::{BTreeMap, HashMap};
use std::ffi::CString;
use std::fs::File;
use std::ops::DerefMut;
use std::os::unix::io::AsRawFd;
use std::os::unix::prelude::{FromRawFd, IntoRawFd};
use std::process::{Command, Stdio};
use std::rc::Rc;
use std::{convert::TryInto, io::Seek};
Expand Down Expand Up @@ -122,10 +123,9 @@ impl<'a> CommitRewriter<'a> {
// If we're operating on a bare repo, we can clone the file (copy_file_range) directly.
if let Ok(instream) = instream.clone().downcast::<gio::UnixInputStream>() {
// View the fd as a File
let instream_fd = unsafe { File::from_raw_fd(instream.as_raw_fd()) };
instream_fd.copy_to(tempf.as_file_mut())?;
// Leak to avoid double close
let _ = instream_fd.into_raw_fd();
let instream_fd = unsafe { BorrowedFd::borrow_raw_fd(instream.as_raw_fd()) };
let instream_fd = &mut instream_fd.as_filelike_view::<File>();
std::io::copy(instream_fd.deref_mut(), tempf.as_file_mut())?;
} else {
// If we're operating on an archive repo, then we need to uncompress
// and recompress...
Expand Down

0 comments on commit 0581c26

Please sign in to comment.