mirror of
https://github.com/lsd-rs/lsd
synced 2024-12-14 22:22:26 +00:00
Format code using 'cargo fmt'
This commit is contained in:
parent
822aec4b22
commit
f619dc07d6
6 changed files with 44 additions and 39 deletions
|
@ -282,7 +282,7 @@ fn get_visible_width(input: &str) -> usize {
|
||||||
if input.starts_with("\u{1b}[") {
|
if input.starts_with("\u{1b}[") {
|
||||||
let m_pos = input.find('m');
|
let m_pos = input.find('m');
|
||||||
if let Some(len) = m_pos {
|
if let Some(len) = m_pos {
|
||||||
nb_invisible_char = len + 3 // 1 (index -> length) + 2 ( compensate for color reset chars )
|
nb_invisible_char = len + 3 // 1 (index -> length) + 2 ( compensate for color reset chars )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,10 +61,10 @@ mod test {
|
||||||
use crate::color::{Colors, Theme};
|
use crate::color::{Colors, Theme};
|
||||||
use crate::flags::{DateFlag, Flags};
|
use crate::flags::{DateFlag, Flags};
|
||||||
use ansi_term::Colour;
|
use ansi_term::Colour;
|
||||||
use std::{env, fs};
|
|
||||||
use std::process::{Command, ExitStatus};
|
|
||||||
use std::path::Path;
|
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use std::path::Path;
|
||||||
|
use std::process::{Command, ExitStatus};
|
||||||
|
use std::{env, fs};
|
||||||
use time;
|
use time;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
|
|
@ -90,9 +90,9 @@ impl FileType {
|
||||||
mod test {
|
mod test {
|
||||||
use super::FileType;
|
use super::FileType;
|
||||||
use crate::color::{Colors, Theme};
|
use crate::color::{Colors, Theme};
|
||||||
|
use crate::meta::Meta;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use crate::meta::Permissions;
|
use crate::meta::Permissions;
|
||||||
use crate::meta::Meta;
|
|
||||||
use ansi_term::Colour;
|
use ansi_term::Colour;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
@ -123,7 +123,8 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_dir_type() {
|
fn test_dir_type() {
|
||||||
let tmp_dir = TempDir::new("test_dir_type").expect("failed to create temp dir");
|
let tmp_dir = TempDir::new("test_dir_type").expect("failed to create temp dir");
|
||||||
let meta = Meta::from_path(&tmp_dir.path().to_path_buf()).expect("failed to get tempdir path");
|
let meta =
|
||||||
|
Meta::from_path(&tmp_dir.path().to_path_buf()).expect("failed to get tempdir path");
|
||||||
let metadata = tmp_dir.path().metadata().expect("failed to get metas");
|
let metadata = tmp_dir.path().metadata().expect("failed to get metas");
|
||||||
|
|
||||||
let colors = Colors::new(Theme::NoLscolors);
|
let colors = Colors::new(Theme::NoLscolors);
|
||||||
|
|
|
@ -6,7 +6,7 @@ use std::path::Path;
|
||||||
|
|
||||||
#[derive(Debug, Eq)]
|
#[derive(Debug, Eq)]
|
||||||
pub struct Name {
|
pub struct Name {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
path: String,
|
path: String,
|
||||||
extension: Option<String>,
|
extension: Option<String>,
|
||||||
file_type: FileType,
|
file_type: FileType,
|
||||||
|
@ -95,8 +95,8 @@ mod test {
|
||||||
use super::Name;
|
use super::Name;
|
||||||
use crate::color::{self, Colors};
|
use crate::color::{self, Colors};
|
||||||
use crate::icon::{self, Icons};
|
use crate::icon::{self, Icons};
|
||||||
use crate::meta::Meta;
|
|
||||||
use crate::meta::FileType;
|
use crate::meta::FileType;
|
||||||
|
use crate::meta::Meta;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use crate::meta::Permissions;
|
use crate::meta::Permissions;
|
||||||
use ansi_term::Colour;
|
use ansi_term::Colour;
|
||||||
|
|
|
@ -11,10 +11,7 @@ pub struct Owner {
|
||||||
impl Owner {
|
impl Owner {
|
||||||
#[cfg_attr(unix, allow(dead_code))]
|
#[cfg_attr(unix, allow(dead_code))]
|
||||||
pub fn new(user: String, group: String) -> Self {
|
pub fn new(user: String, group: String) -> Self {
|
||||||
Self {
|
Self { user, group }
|
||||||
user,
|
|
||||||
group,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
use std::io;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::ffi::{OsStr, OsString};
|
use std::ffi::{OsStr, OsString};
|
||||||
|
use std::io;
|
||||||
|
use std::os::windows::ffi::{OsStrExt, OsStringExt};
|
||||||
|
use std::path::PathBuf;
|
||||||
use std::ptr::null_mut;
|
use std::ptr::null_mut;
|
||||||
use std::os::windows::ffi::{OsStringExt, OsStrExt};
|
|
||||||
|
|
||||||
use winapi::um::winnt;
|
|
||||||
use winapi::um::accctrl::TRUSTEE_W;
|
|
||||||
use winapi::shared::winerror;
|
|
||||||
use winapi::ctypes::c_void;
|
use winapi::ctypes::c_void;
|
||||||
|
use winapi::shared::winerror;
|
||||||
|
use winapi::um::accctrl::TRUSTEE_W;
|
||||||
|
use winapi::um::winnt;
|
||||||
|
|
||||||
use super::{Owner, Permissions};
|
use super::{Owner, Permissions};
|
||||||
|
|
||||||
const BUF_SIZE: u32 = 256;
|
const BUF_SIZE: u32 = 256;
|
||||||
|
|
||||||
|
|
||||||
pub fn get_file_data(path: &PathBuf) -> Result<(Owner, Permissions), io::Error> {
|
pub fn get_file_data(path: &PathBuf) -> Result<(Owner, Permissions), io::Error> {
|
||||||
// Overall design:
|
// Overall design:
|
||||||
// This function allocates some data with GetNamedSecurityInfoW,
|
// This function allocates some data with GetNamedSecurityInfoW,
|
||||||
|
@ -54,12 +53,12 @@ pub fn get_file_data(path: &PathBuf) -> Result<(Owner, Permissions), io::Error>
|
||||||
&mut group_sid_ptr,
|
&mut group_sid_ptr,
|
||||||
&mut dacl_ptr,
|
&mut dacl_ptr,
|
||||||
null_mut(),
|
null_mut(),
|
||||||
&mut sd_ptr
|
&mut sd_ptr,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
if error_code != winerror::ERROR_SUCCESS {
|
if error_code != winerror::ERROR_SUCCESS {
|
||||||
return Err(std::io::Error::from_raw_os_error(error_code as i32))
|
return Err(std::io::Error::from_raw_os_error(error_code as i32));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assumptions:
|
// Assumptions:
|
||||||
|
@ -106,17 +105,21 @@ pub fn get_file_data(path: &PathBuf) -> Result<(Owner, Permissions), io::Error>
|
||||||
winnt::WinWorldSid,
|
winnt::WinWorldSid,
|
||||||
null_mut(),
|
null_mut(),
|
||||||
world_sid.as_mut_ptr() as *mut _,
|
world_sid.as_mut_ptr() as *mut _,
|
||||||
&mut world_sid_len)
|
&mut world_sid_len,
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
if result == 0 {
|
if result == 0 {
|
||||||
// Failed to create the SID
|
// Failed to create the SID
|
||||||
// Assumptions: Same as the other identical calls
|
// Assumptions: Same as the other identical calls
|
||||||
unsafe { winapi::um::winbase::LocalFree(sd_ptr); }
|
unsafe {
|
||||||
|
winapi::um::winbase::LocalFree(sd_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
// Assumptions: None (GetLastError shouldn't ever fail)
|
// Assumptions: None (GetLastError shouldn't ever fail)
|
||||||
return Err(io::Error::from_raw_os_error(
|
return Err(io::Error::from_raw_os_error(unsafe {
|
||||||
unsafe { winapi::um::errhandlingapi::GetLastError() } as i32));
|
winapi::um::errhandlingapi::GetLastError()
|
||||||
|
} as i32));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assumptions:
|
// Assumptions:
|
||||||
|
@ -129,17 +132,11 @@ pub fn get_file_data(path: &PathBuf) -> Result<(Owner, Permissions), io::Error>
|
||||||
// Assumptions:
|
// Assumptions:
|
||||||
// - xxxxx_trustee are still valid (including underlying SID)
|
// - xxxxx_trustee are still valid (including underlying SID)
|
||||||
// - dacl_ptr is still valid
|
// - dacl_ptr is still valid
|
||||||
let owner_access_mask = unsafe {
|
let owner_access_mask = unsafe { get_acl_access_mask(dacl_ptr as *mut _, &mut owner_trustee) }?;
|
||||||
get_acl_access_mask(dacl_ptr as *mut _, &mut owner_trustee)
|
|
||||||
}?;
|
|
||||||
|
|
||||||
let group_access_mask = unsafe {
|
let group_access_mask = unsafe { get_acl_access_mask(dacl_ptr as *mut _, &mut group_trustee) }?;
|
||||||
get_acl_access_mask(dacl_ptr as *mut _, &mut group_trustee)
|
|
||||||
}?;
|
|
||||||
|
|
||||||
let world_access_mask = unsafe {
|
let world_access_mask = unsafe { get_acl_access_mask(dacl_ptr as *mut _, &mut world_trustee) }?;
|
||||||
get_acl_access_mask(dacl_ptr as *mut _, &mut world_trustee)
|
|
||||||
}?;
|
|
||||||
|
|
||||||
let has_bit = |field: u32, bit: u32| field & bit != 0;
|
let has_bit = |field: u32, bit: u32| field & bit != 0;
|
||||||
|
|
||||||
|
@ -167,7 +164,9 @@ pub fn get_file_data(path: &PathBuf) -> Result<(Owner, Permissions), io::Error>
|
||||||
// - The free succeeds (currently unchecked -- there's no real recovery
|
// - The free succeeds (currently unchecked -- there's no real recovery
|
||||||
// options. It's not much memory, so leaking it on failure is
|
// options. It's not much memory, so leaking it on failure is
|
||||||
// *probably* fine)
|
// *probably* fine)
|
||||||
unsafe { winapi::um::winbase::LocalFree(sd_ptr); }
|
unsafe {
|
||||||
|
winapi::um::winbase::LocalFree(sd_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
Ok((owner, permissions))
|
Ok((owner, permissions))
|
||||||
}
|
}
|
||||||
|
@ -178,7 +177,10 @@ pub fn get_file_data(path: &PathBuf) -> Result<(Owner, Permissions), io::Error>
|
||||||
/// - acl_ptr points to a valid ACL data structure
|
/// - acl_ptr points to a valid ACL data structure
|
||||||
/// - trustee_ptr points to a valid trustee data structure
|
/// - trustee_ptr points to a valid trustee data structure
|
||||||
/// - Both remain valid through the function call (no long-term requirement)
|
/// - Both remain valid through the function call (no long-term requirement)
|
||||||
unsafe fn get_acl_access_mask(acl_ptr: *mut c_void, trustee_ptr: *mut TRUSTEE_W) -> Result<u32, io::Error> {
|
unsafe fn get_acl_access_mask(
|
||||||
|
acl_ptr: *mut c_void,
|
||||||
|
trustee_ptr: *mut TRUSTEE_W,
|
||||||
|
) -> Result<u32, io::Error> {
|
||||||
let mut access_mask = 0;
|
let mut access_mask = 0;
|
||||||
|
|
||||||
// Assumptions:
|
// Assumptions:
|
||||||
|
@ -187,7 +189,8 @@ unsafe fn get_acl_access_mask(acl_ptr: *mut c_void, trustee_ptr: *mut TRUSTEE_W)
|
||||||
let err_code = winapi::um::aclapi::GetEffectiveRightsFromAclW(
|
let err_code = winapi::um::aclapi::GetEffectiveRightsFromAclW(
|
||||||
acl_ptr as *mut _,
|
acl_ptr as *mut _,
|
||||||
trustee_ptr,
|
trustee_ptr,
|
||||||
&mut access_mask);
|
&mut access_mask,
|
||||||
|
);
|
||||||
|
|
||||||
if err_code == winerror::ERROR_SUCCESS {
|
if err_code == winerror::ERROR_SUCCESS {
|
||||||
Ok(access_mask)
|
Ok(access_mask)
|
||||||
|
@ -254,7 +257,9 @@ unsafe fn lookup_account_sid(sid: *mut c_void) -> Result<(Vec<u16>, Vec<u16>), s
|
||||||
} else {
|
} else {
|
||||||
// Some other failure
|
// Some other failure
|
||||||
// Assumptions: None (GetLastError shouldn't ever fail)
|
// Assumptions: None (GetLastError shouldn't ever fail)
|
||||||
return Err(io::Error::from_raw_os_error(winapi::um::errhandlingapi::GetLastError() as i32));
|
return Err(io::Error::from_raw_os_error(
|
||||||
|
winapi::um::errhandlingapi::GetLastError() as i32,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,7 +317,9 @@ mod test {
|
||||||
for msb in 0..=256u16 {
|
for msb in 0..=256u16 {
|
||||||
let val = msb << 8 | lsb;
|
let val = msb << 8 | lsb;
|
||||||
|
|
||||||
if val != 0 { vec.push(val) }
|
if val != 0 {
|
||||||
|
vec.push(val)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vec.push(0);
|
vec.push(0);
|
||||||
|
|
Loading…
Reference in a new issue