From 2a4eaf16ca7175e3ece2a7eb71f37fe19621e0e6 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Sat, 7 Oct 2023 16:40:41 +0900 Subject: [PATCH] Remove SeekExt --- src/hg_connect_http.rs | 4 ++-- src/hg_connect_stdio.rs | 4 ++-- src/util.rs | 13 +------------ 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/hg_connect_http.rs b/src/hg_connect_http.rs index 530aa1178..57331cda5 100644 --- a/src/hg_connect_http.rs +++ b/src/hg_connect_http.rs @@ -43,7 +43,7 @@ use crate::libgit::{ credential_fill, curl_errorstr, die, get_active_slot, http_auth, http_follow_config, run_one_slot, slot_results, ssl_cainfo, HTTP_OK, HTTP_REAUTH, }; -use crate::util::{ImmutBString, OsStrExt, PrefixWriter, ReadExt, SeekExt, SliceExt, ToBoxed}; +use crate::util::{ImmutBString, OsStrExt, PrefixWriter, ReadExt, SliceExt, ToBoxed}; mod git_http_state { use std::ffi::CString; @@ -226,7 +226,7 @@ impl HttpRequest { curl_easy_setopt( slot.curl, CURLOPT_POSTFIELDSIZE_LARGE, - body.stream_len_().unwrap(), + body.seek(SeekFrom::End(0)).unwrap(), ); /* Ensure we have no state from a previous attempt that failed because * of authentication (401). */ diff --git a/src/hg_connect_stdio.rs b/src/hg_connect_stdio.rs index 6d8294b48..1c3712264 100644 --- a/src/hg_connect_stdio.rs +++ b/src/hg_connect_stdio.rs @@ -23,7 +23,7 @@ use crate::hg_connect::{ use crate::libc::FdFile; use crate::libcinnabar::{hg_connect_stdio, stdio_finish}; use crate::libgit::child_process; -use crate::util::{ImmutBString, OsStrExt, PrefixWriter, ReadExt, SeekExt}; +use crate::util::{ImmutBString, OsStrExt, PrefixWriter, ReadExt}; pub struct HgStdioConnection { capabilities: HgCapabilities, @@ -113,7 +113,7 @@ impl HgWireConnection for HgStdioConnection { self.proc_in.write_all(&header).unwrap(); drop(header); - let len = input.stream_len_().unwrap(); + let len = input.metadata().unwrap().len(); //TODO: chunk in smaller pieces. writeln!(self.proc_in, "{}", len).unwrap(); diff --git a/src/util.rs b/src/util.rs index 8dafdced4..4ccd2b793 100644 --- a/src/util.rs +++ b/src/util.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use std::ffi::{CStr, CString, OsStr}; -use std::io::{self, LineWriter, Read, Seek, SeekFrom, Write}; +use std::io::{self, LineWriter, Read, Write}; #[cfg(unix)] use std::os::unix::ffi; #[cfg(windows)] @@ -94,17 +94,6 @@ pub trait ReadExt: Read { impl ReadExt for T {} -pub trait SeekExt: Seek { - fn stream_len_(&mut self) -> io::Result { - let old_pos = self.stream_position()?; - let len = self.seek(SeekFrom::End(0))?; - self.seek(SeekFrom::Start(old_pos))?; - Ok(len) - } -} - -impl SeekExt for T {} - pub trait SliceExt { fn splitn_exact(&self, c: C) -> Option<[&Self; N]>; fn rsplitn_exact(&self, c: C) -> Option<[&Self; N]>;