replace tools::vec with proxmox::tools::vec
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
d0162d53d3
commit
f35197f449
@ -17,8 +17,7 @@ use uuid::Uuid;
|
|||||||
//use chrono::{Local, TimeZone};
|
//use chrono::{Local, TimeZone};
|
||||||
|
|
||||||
use proxmox::tools::io::ReadExt;
|
use proxmox::tools::io::ReadExt;
|
||||||
|
use proxmox::tools::vec;
|
||||||
use crate::tools::vec;
|
|
||||||
|
|
||||||
use super::{DataChunk, DataChunkBuilder};
|
use super::{DataChunk, DataChunkBuilder};
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ use nix::sys::stat::Mode;
|
|||||||
use nix::errno::Errno;
|
use nix::errno::Errno;
|
||||||
use nix::sys::stat::FileStat;
|
use nix::sys::stat::FileStat;
|
||||||
|
|
||||||
use crate::tools::vec;
|
use proxmox::tools::vec;
|
||||||
|
|
||||||
/// The format requires to build sorted directory lookup tables in
|
/// The format requires to build sorted directory lookup tables in
|
||||||
/// memory, so we restrict the number of allowed entries to limit
|
/// memory, so we restrict the number of allowed entries to limit
|
||||||
|
@ -22,8 +22,8 @@ use nix::errno::Errno;
|
|||||||
use nix::NixPath;
|
use nix::NixPath;
|
||||||
|
|
||||||
use proxmox::tools::io::ReadExt;
|
use proxmox::tools::io::ReadExt;
|
||||||
|
use proxmox::tools::vec;
|
||||||
|
|
||||||
use crate::tools::vec;
|
|
||||||
use crate::tools::fs;
|
use crate::tools::fs;
|
||||||
use crate::tools::acl;
|
use crate::tools::acl;
|
||||||
use crate::tools::xattr;
|
use crate::tools::xattr;
|
||||||
|
@ -22,6 +22,8 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
|
use proxmox::tools::vec;
|
||||||
|
|
||||||
pub mod async_mutex;
|
pub mod async_mutex;
|
||||||
pub mod timer;
|
pub mod timer;
|
||||||
pub mod wrapped_reader_stream;
|
pub mod wrapped_reader_stream;
|
||||||
@ -36,7 +38,6 @@ pub mod daemon;
|
|||||||
pub mod procfs;
|
pub mod procfs;
|
||||||
pub mod acl;
|
pub mod acl;
|
||||||
pub mod xattr;
|
pub mod xattr;
|
||||||
pub mod vec;
|
|
||||||
pub mod futures;
|
pub mod futures;
|
||||||
|
|
||||||
mod process_locker;
|
mod process_locker;
|
||||||
|
@ -1,99 +0,0 @@
|
|||||||
//! This module provides additional operations for `Vec<u8>`.
|
|
||||||
//!
|
|
||||||
//! Example:
|
|
||||||
//! ```
|
|
||||||
//! # use std::io::Read;
|
|
||||||
//! use proxmox_backup::tools::vec::{self, ops::*};
|
|
||||||
//!
|
|
||||||
//! fn append_1024_to_vec<T: Read>(mut input: T, buffer: &mut Vec<u8>) -> 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<u8>) -> 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<u8>) -> 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<u8> {
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,8 +4,10 @@ extern crate libc;
|
|||||||
|
|
||||||
use std::os::unix::io::RawFd;
|
use std::os::unix::io::RawFd;
|
||||||
use nix::errno::Errno;
|
use nix::errno::Errno;
|
||||||
|
|
||||||
|
use proxmox::tools::vec;
|
||||||
|
|
||||||
use crate::pxar::{CaFormatXAttr, CaFormatFCaps};
|
use crate::pxar::{CaFormatXAttr, CaFormatFCaps};
|
||||||
use crate::tools::vec;
|
|
||||||
|
|
||||||
pub fn flistxattr(fd: RawFd) -> Result<Vec<u8>, nix::errno::Errno> {
|
pub fn flistxattr(fd: RawFd) -> Result<Vec<u8>, nix::errno::Errno> {
|
||||||
// Initial buffer size for the attribute list, if content does not fit
|
// Initial buffer size for the attribute list, if content does not fit
|
||||||
|
Loading…
Reference in New Issue
Block a user