From f35197f449155eb203ab18f11111c8a98febfb8a Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Mon, 1 Jul 2019 11:03:25 +0200 Subject: [PATCH] replace tools::vec with proxmox::tools::vec Signed-off-by: Wolfgang Bumiller --- src/backup/dynamic_index.rs | 3 +- src/pxar/encoder.rs | 2 +- src/pxar/sequential_decoder.rs | 2 +- src/tools.rs | 3 +- src/tools/vec/ops.rs | 99 ---------------------------------- src/tools/xattr.rs | 4 +- 6 files changed, 8 insertions(+), 105 deletions(-) delete mode 100644 src/tools/vec/ops.rs diff --git a/src/backup/dynamic_index.rs b/src/backup/dynamic_index.rs index 26910884..b616d23a 100644 --- a/src/backup/dynamic_index.rs +++ b/src/backup/dynamic_index.rs @@ -17,8 +17,7 @@ use uuid::Uuid; //use chrono::{Local, TimeZone}; use proxmox::tools::io::ReadExt; - -use crate::tools::vec; +use proxmox::tools::vec; use super::{DataChunk, DataChunkBuilder}; diff --git a/src/pxar/encoder.rs b/src/pxar/encoder.rs index 1482f2fa..163b7745 100644 --- a/src/pxar/encoder.rs +++ b/src/pxar/encoder.rs @@ -28,7 +28,7 @@ use nix::sys::stat::Mode; use nix::errno::Errno; use nix::sys::stat::FileStat; -use crate::tools::vec; +use proxmox::tools::vec; /// The format requires to build sorted directory lookup tables in /// memory, so we restrict the number of allowed entries to limit diff --git a/src/pxar/sequential_decoder.rs b/src/pxar/sequential_decoder.rs index dcb4ebad..5c5e8a69 100644 --- a/src/pxar/sequential_decoder.rs +++ b/src/pxar/sequential_decoder.rs @@ -22,8 +22,8 @@ use nix::errno::Errno; use nix::NixPath; use proxmox::tools::io::ReadExt; +use proxmox::tools::vec; -use crate::tools::vec; use crate::tools::fs; use crate::tools::acl; use crate::tools::xattr; diff --git a/src/tools.rs b/src/tools.rs index d288e976..3c1c711d 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -22,6 +22,8 @@ use std::collections::HashMap; use serde_json::Value; +use proxmox::tools::vec; + pub mod async_mutex; pub mod timer; pub mod wrapped_reader_stream; @@ -36,7 +38,6 @@ pub mod daemon; pub mod procfs; pub mod acl; pub mod xattr; -pub mod vec; pub mod futures; mod process_locker; diff --git a/src/tools/vec/ops.rs b/src/tools/vec/ops.rs deleted file mode 100644 index 8b3f3ba0..00000000 --- a/src/tools/vec/ops.rs +++ /dev/null @@ -1,99 +0,0 @@ -//! This module provides additional operations for `Vec`. -//! -//! Example: -//! ``` -//! # use std::io::Read; -//! use proxmox_backup::tools::vec::{self, ops::*}; -//! -//! fn append_1024_to_vec(mut input: T, buffer: &mut Vec) -> std::io::Result<()> { -//! input.read_exact(unsafe { buffer.grow_uninitialized(1024) }) -//! } -//! ``` - -/// Some additional byte vector operations useful for I/O code. -/// Example: -/// ``` -/// # use std::io::Read; -/// # use proxmox_backup::tools::io::{self, ops::*}; -/// use proxmox_backup::tools::vec::{self, ops::*}; -/// -/// # fn code(mut file: std::fs::File, mut data: Vec) -> std::io::Result<()> { -/// file.read_exact(unsafe { -/// data.grow_uninitialized(1024) -/// })?; -/// # Ok(()) -/// # } -/// ``` -/// -/// Note that this module also provides a safe alternative for the case where -/// `grow_uninitialized()` is directly followed by a `read_exact()` call via the [`ReadExtOps`] -/// trait: -/// ```ignore -/// file.append_to_vec(&mut data, 1024)?; -/// ``` -/// -/// [`ReadExtOps`]: crate::tools::io::ops::ReadExtOps -pub trait VecU8ExtOps { - /// Grow a vector without initializing its elements. The difference to simply using `reserve` - /// is that it also updates the actual length, making the newly allocated data part of the - /// slice. - /// - /// This is a shortcut for: - /// ```ignore - /// vec.reserve(more); - /// let total = vec.len() + more; - /// unsafe { - /// vec.set_len(total); - /// } - /// ``` - /// - /// This returns a mutable slice to the newly allocated space, so it can be used inline: - /// ``` - /// # use std::io::Read; - /// # use proxmox_backup::tools::vec::ops::*; - /// # fn test(mut file: std::fs::File, buffer: &mut Vec) -> std::io::Result<()> { - /// file.read_exact(unsafe { buffer.grow_uninitialized(1024) })?; - /// # Ok(()) - /// # } - /// ``` - /// - /// Although for the above case it is recommended to use the even shorter version from the - /// [`ReadExtOps`] trait: - /// ```ignore - /// // use crate::tools::vec::ops::ReadExtOps; - /// file.append_to_vec(&mut buffer, 1024)?; - /// ``` - /// - /// [`ReadExtOps`]: crate::tools::io::ops::ReadExtOps - unsafe fn grow_uninitialized(&mut self, more: usize) -> &mut [u8]; - - /// Resize a vector to a specific size without initializing its data. This is a shortcut for: - /// ```ignore - /// if new_size <= vec.len() { - /// vec.truncate(new_size); - /// } else { - /// unsafe { - /// vec.grow_uninitialized(new_size - vec.len()); - /// } - /// } - /// ``` - unsafe fn resize_uninitialized(&mut self, total: usize); -} - -impl VecU8ExtOps for Vec { - unsafe fn grow_uninitialized(&mut self, more: usize) -> &mut [u8] { - let old_len = self.len(); - self.reserve(more); - let total = old_len + more; - self.set_len(total); - &mut self[old_len..] - } - - unsafe fn resize_uninitialized(&mut self, new_size: usize) { - if new_size <= self.len() { - self.truncate(new_size); - } else { - self.grow_uninitialized(new_size - self.len()); - } - } -} diff --git a/src/tools/xattr.rs b/src/tools/xattr.rs index 58decc52..864ab3ac 100644 --- a/src/tools/xattr.rs +++ b/src/tools/xattr.rs @@ -4,8 +4,10 @@ extern crate libc; use std::os::unix::io::RawFd; use nix::errno::Errno; + +use proxmox::tools::vec; + use crate::pxar::{CaFormatXAttr, CaFormatFCaps}; -use crate::tools::vec; pub fn flistxattr(fd: RawFd) -> Result, nix::errno::Errno> { // Initial buffer size for the attribute list, if content does not fit