mirror of
https://github.com/lsd-rs/lsd
synced 2024-12-14 22:22:26 +00:00
Display "-" instead of "-\-" by handling the error immediately
This commit is contained in:
parent
b45c7550b6
commit
8cea3695cb
1 changed files with 32 additions and 14 deletions
|
@ -61,26 +61,42 @@ pub fn get_file_data(path: &Path) -> Result<(Owner, Permissions), io::Error> {
|
|||
return Err(std::io::Error::from_raw_os_error(error_code as i32));
|
||||
}
|
||||
|
||||
// Format into domain\name format
|
||||
|
||||
// Assumptions:
|
||||
// - owner_sid_ptr is valid
|
||||
// - group_sid_ptr is valid
|
||||
// (both OK because GetNamedSecurityInfoW returned success)
|
||||
let (owner_name, owner_domain) = unsafe { lookup_account_sid(owner_sid_ptr) }?;
|
||||
let (group_name, group_domain) = unsafe { lookup_account_sid(group_sid_ptr) }?;
|
||||
|
||||
let owner_name = os_from_buf(&owner_name);
|
||||
let owner_domain = os_from_buf(&owner_domain);
|
||||
let group_name = os_from_buf(&group_name);
|
||||
let group_domain = os_from_buf(&group_domain);
|
||||
let mut owner = String::new();
|
||||
match unsafe { lookup_account_sid(owner_sid_ptr) } {
|
||||
Ok((n, d)) => {
|
||||
let owner_name = os_from_buf(&n);
|
||||
let owner_domain = os_from_buf(&d);
|
||||
|
||||
// Format into domain\name format
|
||||
let mut owner = owner_domain.to_string_lossy().into_owned();
|
||||
owner.push('\\');
|
||||
owner.push_str(&owner_name.to_string_lossy());
|
||||
let mut owner = owner_domain.to_string_lossy().into_owned();
|
||||
owner.push('\\');
|
||||
owner.push_str(&owner_name.to_string_lossy());
|
||||
}
|
||||
Err(_) => {
|
||||
owner.push('-');
|
||||
}
|
||||
};
|
||||
|
||||
let mut group = group_domain.to_string_lossy().into_owned();
|
||||
group.push('\\');
|
||||
group.push_str(&group_name.to_string_lossy());
|
||||
let mut group = String::new();
|
||||
match unsafe { lookup_account_sid(group_sid_ptr) } {
|
||||
Ok((n, d)) => {
|
||||
let group_name = os_from_buf(&n);
|
||||
let group_domain = os_from_buf(&d);
|
||||
|
||||
let mut group = group_domain.to_string_lossy().into_owned();
|
||||
group.push('\\');
|
||||
group.push_str(&group_name.to_string_lossy());
|
||||
}
|
||||
Err(_) => {
|
||||
group.push('-');
|
||||
}
|
||||
};
|
||||
|
||||
// This structure will be returned
|
||||
let owner = Owner::new(owner, group);
|
||||
|
@ -258,7 +274,9 @@ unsafe fn lookup_account_sid(sid: *mut c_void) -> Result<(Vec<u16>, Vec<u16>), s
|
|||
// Unknown account and or system domain identification
|
||||
// Possibly foreign item originating from another machine
|
||||
// TODO: Calculate permissions since it has to be possible if Explorer knows.
|
||||
return Ok((vec!['-' as u16], vec!['-' as u16]));
|
||||
return Err(io::Error::from_raw_os_error(
|
||||
winapi::um::errhandlingapi::GetLastError() as i32,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue