mirror of
https://github.com/lsd-rs/lsd
synced 2024-12-14 14:12:31 +00:00
Compiles on Windows with new windows_utils module
windows_utils will be responsible for safely wrapping WinAPI calls. This should result in minimal changes to the interfaces of the existing modules: all that is needed is new (very simple) constructors.
This commit is contained in:
parent
0dbc3b3a62
commit
6a022c01bf
7 changed files with 39 additions and 6 deletions
|
@ -25,11 +25,13 @@ libc = "0.2.44"
|
|||
term_grid = "0.1.7"
|
||||
terminal_size = "0.1.8"
|
||||
time = "0.1.40"
|
||||
users = "0.8.0"
|
||||
chrono-humanize = "0.0.11"
|
||||
unicode-width = "0.1.5"
|
||||
lscolors = "0.5.0"
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
users = "0.8.0"
|
||||
|
||||
[dependencies.clap]
|
||||
features = ["suggestions", "color", "wrap_help"]
|
||||
version = "2.32.0"
|
||||
|
|
|
@ -17,6 +17,8 @@ extern crate term_grid;
|
|||
extern crate terminal_size;
|
||||
extern crate time;
|
||||
extern crate unicode_width;
|
||||
|
||||
#[cfg(unix)]
|
||||
extern crate users;
|
||||
|
||||
mod app;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use crate::color::{ColoredString, Colors, Elem};
|
||||
use crate::meta::Permissions;
|
||||
use std::fs::Metadata;
|
||||
use std::os::unix::fs::FileTypeExt;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub enum FileType {
|
||||
|
@ -16,7 +15,10 @@ pub enum FileType {
|
|||
}
|
||||
|
||||
impl FileType {
|
||||
#[cfg(unix)]
|
||||
pub fn new(meta: &Metadata, permissions: &Permissions) -> Self {
|
||||
use std::os::unix::fs::FileTypeExt;
|
||||
|
||||
let file_type = meta.file_type();
|
||||
|
||||
if file_type.is_file() {
|
||||
|
@ -42,6 +44,11 @@ impl FileType {
|
|||
FileType::Special
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
pub fn new(meta: &Metadata, permissions: &Permissions) -> Self {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl FileType {
|
||||
|
|
|
@ -7,6 +7,9 @@ mod permissions;
|
|||
mod size;
|
||||
mod symlink;
|
||||
|
||||
#[cfg(windows)]
|
||||
mod windows_utils;
|
||||
|
||||
pub use self::date::Date;
|
||||
pub use self::filetype::FileType;
|
||||
pub use self::indicator::Indicator;
|
||||
|
@ -120,7 +123,14 @@ impl Meta {
|
|||
path.metadata()?
|
||||
};
|
||||
|
||||
#[cfg(unix)]
|
||||
let owner = Owner::from(&metadata);
|
||||
#[cfg(unix)]
|
||||
let permissions = Permissions::from(&metadata);
|
||||
|
||||
#[cfg(windows)]
|
||||
let (owner, permissions) = windows_utils::get_file_data(&path)?;
|
||||
|
||||
let file_type = FileType::new(&metadata, &permissions);
|
||||
let name = Name::new(&path, file_type);
|
||||
|
||||
|
@ -130,7 +140,7 @@ impl Meta {
|
|||
size: Size::from(&metadata),
|
||||
date: Date::from(&metadata),
|
||||
indicator: Indicator::from(file_type),
|
||||
owner: Owner::from(&metadata),
|
||||
owner,
|
||||
permissions,
|
||||
name,
|
||||
file_type,
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
use crate::color::{ColoredString, Colors, Elem};
|
||||
use std::fs::Metadata;
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
use users::{get_group_by_gid, get_user_by_uid};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Owner {
|
||||
|
@ -9,8 +7,12 @@ pub struct Owner {
|
|||
group: String,
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
impl<'a> From<&'a Metadata> for Owner {
|
||||
fn from(meta: &Metadata) -> Self {
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
use users::{get_group_by_gid, get_user_by_uid};
|
||||
|
||||
let user = match get_user_by_uid(meta.uid()) {
|
||||
Some(res) => res.name().to_string_lossy().to_string(),
|
||||
None => meta.uid().to_string(),
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use crate::color::{ColoredString, Colors, Elem};
|
||||
use ansi_term::ANSIStrings;
|
||||
use std::fs::Metadata;
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub struct Permissions {
|
||||
|
@ -22,8 +21,11 @@ pub struct Permissions {
|
|||
pub setuid: bool,
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
impl<'a> From<&'a Metadata> for Permissions {
|
||||
fn from(meta: &Metadata) -> Self {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
|
||||
let bits = meta.permissions().mode();
|
||||
let has_bit = |bit| bits & bit == bit;
|
||||
|
||||
|
@ -98,6 +100,7 @@ impl Permissions {
|
|||
|
||||
// More readable aliases for the permission bits exposed by libc.
|
||||
#[allow(trivial_numeric_casts)]
|
||||
#[cfg(unix)]
|
||||
mod modes {
|
||||
use libc;
|
||||
|
||||
|
|
7
src/meta/windows_utils.rs
Normal file
7
src/meta/windows_utils.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
use super::{Owner, Permissions};
|
||||
|
||||
pub fn get_file_data(path: &PathBuf) -> Result<(Owner, Permissions), io::Error> {
|
||||
unimplemented!()
|
||||
}
|
Loading…
Reference in a new issue