mirror of
https://github.com/eza-community/eza.git
synced 2025-12-23 05:36:50 +00:00
Tree-wide: Fix Windows build
This commit is contained in:
parent
f485a8d753
commit
91cb875dc3
8 changed files with 61 additions and 15 deletions
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
#![allow(trivial_casts)] // for ARM
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
||||
use std::cmp::Ordering;
|
||||
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
||||
use std::ffi::CString;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
|
|
@ -94,6 +96,7 @@ fn get_secattr(lister: &lister::Lister, c_path: &std::ffi::CString) -> io::Resul
|
|||
}])
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn list_attrs(lister: &lister::Lister, path: &Path) -> io::Result<Vec<Attribute>> {
|
||||
let c_path = CString::new(path.to_str().ok_or(io::Error::new(io::ErrorKind::Other, "Error: path not convertible to string"))?).map_err(|e| {
|
||||
io::Error::new(io::ErrorKind::Other, e)
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ pub struct Inode(pub ino_t);
|
|||
|
||||
/// A file's size of allocated file system blocks.
|
||||
#[derive(Copy, Clone)]
|
||||
#[cfg(unix)]
|
||||
pub enum Blocksize {
|
||||
|
||||
/// This file has the given number of blocks.
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@ use std::os::unix::fs::{FileTypeExt, MetadataExt, PermissionsExt};
|
|||
#[cfg(windows)]
|
||||
use std::os::windows::fs::MetadataExt;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
use std::time::SystemTime;
|
||||
#[cfg(unix)]
|
||||
use std::time::{Duration, UNIX_EPOCH};
|
||||
|
||||
use log::*;
|
||||
|
||||
|
|
@ -361,6 +363,7 @@ impl<'dir> File<'dir> {
|
|||
|
||||
/// The ID of the user that own this file. If dereferencing links, the links
|
||||
/// may be broken, in which case `None` will be returned.
|
||||
#[cfg(unix)]
|
||||
pub fn user(&self) -> Option<f::User> {
|
||||
if self.is_link() && self.deref_links {
|
||||
match self.link_target_recurse() {
|
||||
|
|
@ -372,6 +375,7 @@ impl<'dir> File<'dir> {
|
|||
}
|
||||
|
||||
/// The ID of the group that owns this file.
|
||||
#[cfg(unix)]
|
||||
pub fn group(&self) -> Option<f::Group> {
|
||||
if self.is_link() && self.deref_links {
|
||||
match self.link_target_recurse() {
|
||||
|
|
@ -431,7 +435,6 @@ impl<'dir> File<'dir> {
|
|||
// The naive approach, as one would think that this info may have been cached.
|
||||
// but as mentioned in the size function comment above, different filesystems
|
||||
// make it difficult to get any info about a dir by it's size, so this may be it.
|
||||
#[cfg(unix)]
|
||||
pub fn is_empty_dir(&self) -> bool {
|
||||
if self.is_directory() {
|
||||
match Dir::read_dir(self.path.clone()) {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
use ansi_term::Style;
|
||||
#[cfg(unix)]
|
||||
use locale::Numeric as NumericLocale;
|
||||
|
||||
#[cfg(unix)]
|
||||
use crate::fs::fields as f;
|
||||
#[cfg(unix)]
|
||||
use crate::output::cell::TextCell;
|
||||
|
||||
|
||||
#[cfg(unix)]
|
||||
impl f::Links {
|
||||
pub fn render<C: Colours>(&self, colours: &C, numeric: &NumericLocale) -> TextCell {
|
||||
let style = if self.multiple { colours.multi_link_file() }
|
||||
|
|
@ -24,11 +27,14 @@ pub trait Colours {
|
|||
#[cfg(test)]
|
||||
pub mod test {
|
||||
use super::Colours;
|
||||
#[cfg(unix)]
|
||||
use crate::output::cell::{TextCell, DisplayWidth};
|
||||
#[cfg(unix)]
|
||||
use crate::fs::fields as f;
|
||||
|
||||
use ansi_term::Colour::*;
|
||||
use ansi_term::Style;
|
||||
#[cfg(unix)]
|
||||
use locale;
|
||||
|
||||
|
||||
|
|
@ -41,6 +47,7 @@ pub mod test {
|
|||
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn regular_file() {
|
||||
let stati = f::Links {
|
||||
count: 1,
|
||||
|
|
@ -56,6 +63,7 @@ pub mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn regular_directory() {
|
||||
let stati = f::Links {
|
||||
count: 3005,
|
||||
|
|
@ -71,6 +79,7 @@ pub mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn popular_file() {
|
||||
let stati = f::Links {
|
||||
count: 3005,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
#[cfg(unix)]
|
||||
mod blocks;
|
||||
#[cfg(unix)]
|
||||
pub use self::blocks::Colours as BlocksColours;
|
||||
|
||||
mod filetype;
|
||||
|
|
@ -12,6 +14,7 @@ mod groups;
|
|||
#[cfg(unix)]
|
||||
pub use self::groups::{Colours as GroupColours, Render as GroupRender};
|
||||
|
||||
#[cfg(unix)]
|
||||
mod inode;
|
||||
// inode uses just one colour
|
||||
|
||||
|
|
@ -32,6 +35,7 @@ pub use self::times::Render as TimeRender;
|
|||
mod users;
|
||||
#[cfg(unix)]
|
||||
pub use self::users::Colours as UserColours;
|
||||
#[cfg(unix)]
|
||||
pub use self::users::Render as UserRender;
|
||||
|
||||
mod octal;
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ pub trait PermissionsPlusRender {
|
|||
fn render<C: Colours+FiletypeColours>(&self, colours: &C) -> TextCell;
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
impl PermissionsPlusRender for Option<f::PermissionsPlus> {
|
||||
#[cfg(unix)]
|
||||
fn render<C: Colours+FiletypeColours>(&self, colours: &C) -> TextCell {
|
||||
match self {
|
||||
Some(p) => {
|
||||
|
|
@ -42,13 +42,23 @@ impl PermissionsPlusRender for Option<f::PermissionsPlus> {
|
|||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
pub fn render<C: Colours+FiletypeColours>(&self, colours: &C) -> TextCell {
|
||||
let mut chars = vec![ self.attributes.render_type(colours) ];
|
||||
chars.extend(self.attributes.render(colours));
|
||||
fn render<C: Colours+FiletypeColours>(&self, colours: &C) -> TextCell {
|
||||
match self {
|
||||
Some(p) => {
|
||||
let mut chars = vec![ p.attributes.render_type(colours) ];
|
||||
chars.extend(p.attributes.render(colours));
|
||||
|
||||
TextCell {
|
||||
width: DisplayWidth::from(chars.len()),
|
||||
contents: chars.into(),
|
||||
TextCell {
|
||||
width: DisplayWidth::from(chars.len()),
|
||||
contents: chars.into(),
|
||||
}
|
||||
},
|
||||
None => {
|
||||
TextCell {
|
||||
width: DisplayWidth::from(0),
|
||||
contents: vec![].into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
use std::cmp::max;
|
||||
#[cfg(unix)]
|
||||
use std::env;
|
||||
use std::ops::Deref;
|
||||
#[cfg(unix)]
|
||||
use std::sync::{Mutex, MutexGuard};
|
||||
|
||||
use datetime::TimeZone;
|
||||
use zoneinfo_compiled::{CompiledData, Result as TZResult};
|
||||
#[cfg(unix)]
|
||||
use zoneinfo_compiled::CompiledData;
|
||||
use zoneinfo_compiled::Result as TZResult;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use log::*;
|
||||
|
|
@ -15,11 +18,11 @@ use uzers::UsersCache;
|
|||
use crate::fs::{File, fields as f};
|
||||
use crate::fs::feature::git::GitCache;
|
||||
use crate::output::cell::TextCell;
|
||||
use crate::output::render::{PermissionsPlusRender, TimeRender};
|
||||
#[cfg(unix)]
|
||||
use crate::output::render::{
|
||||
GroupRender,
|
||||
OctalPermissionsRender,
|
||||
PermissionsPlusRender,
|
||||
TimeRender,
|
||||
UserRender
|
||||
};
|
||||
use crate::output::time::TimeFormat;
|
||||
|
|
@ -104,6 +107,7 @@ impl Columns {
|
|||
columns.push(Column::Group);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
if self.security_context {
|
||||
columns.push(Column::SecurityContext);
|
||||
}
|
||||
|
|
@ -429,6 +433,7 @@ pub struct Table<'a> {
|
|||
widths: TableWidths,
|
||||
time_format: TimeFormat,
|
||||
size_format: SizeFormat,
|
||||
#[cfg(unix)]
|
||||
user_format: UserFormat,
|
||||
git: Option<&'a GitCache>,
|
||||
}
|
||||
|
|
@ -452,6 +457,7 @@ impl<'a> Table<'a> {
|
|||
env,
|
||||
time_format: options.time_format,
|
||||
size_format: options.size_format,
|
||||
#[cfg(unix)]
|
||||
user_format: options.user_format,
|
||||
}
|
||||
}
|
||||
|
|
@ -480,14 +486,22 @@ impl<'a> Table<'a> {
|
|||
self.widths.add_widths(row);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn permissions_plus(&self, file: &File<'_>, xattrs: bool) -> Option<f::PermissionsPlus> {
|
||||
file.permissions().map(|p| f::PermissionsPlus {
|
||||
file_type: file.type_char(),
|
||||
#[cfg(unix)]
|
||||
permissions: p,
|
||||
xattrs
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn permissions_plus(&self, file: &File<'_>, xattrs: bool) -> Option<f::PermissionsPlus> {
|
||||
Some(f::PermissionsPlus {
|
||||
file_type: file.type_char(),
|
||||
#[cfg(windows)]
|
||||
attributes: file.attributes(),
|
||||
xattrs
|
||||
xattrs,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -201,6 +201,7 @@ impl ExtensionMappings {
|
|||
|
||||
|
||||
|
||||
#[cfg(unix)]
|
||||
impl render::BlocksColours for Theme {
|
||||
fn blocksize(&self, prefix: Option<number_prefix::Prefix>) -> Style {
|
||||
use number_prefix::Prefix::*;
|
||||
|
|
@ -374,6 +375,7 @@ fn apply_overlay(mut base: Style, overlay: Style) -> Style {
|
|||
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(unix)]
|
||||
mod customs_test {
|
||||
use super::*;
|
||||
use crate::theme::ui_styles::UiStyles;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue