From 91cb875dc32dc3fc0414dae2c5ac8b500580effb Mon Sep 17 00:00:00 2001 From: Steven Davies Date: Sun, 27 Aug 2023 16:25:37 +0100 Subject: [PATCH] Tree-wide: Fix Windows build --- src/fs/feature/xattr.rs | 3 +++ src/fs/fields.rs | 1 + src/fs/file.rs | 7 +++++-- src/output/render/links.rs | 11 ++++++++++- src/output/render/mod.rs | 4 ++++ src/output/render/permissions.rs | 24 +++++++++++++++++------- src/output/table.rs | 24 +++++++++++++++++++----- src/theme/mod.rs | 2 ++ 8 files changed, 61 insertions(+), 15 deletions(-) diff --git a/src/fs/feature/xattr.rs b/src/fs/feature/xattr.rs index 107e29ed..58e58bbc 100644 --- a/src/fs/feature/xattr.rs +++ b/src/fs/feature/xattr.rs @@ -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> { 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) diff --git a/src/fs/fields.rs b/src/fs/fields.rs index 4ed9f344..2aa95ae4 100644 --- a/src/fs/fields.rs +++ b/src/fs/fields.rs @@ -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. diff --git a/src/fs/file.rs b/src/fs/file.rs index d24b5734..8491efe4 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -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 { 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 { 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()) { diff --git a/src/output/render/links.rs b/src/output/render/links.rs index 612a5d36..1ec62081 100644 --- a/src/output/render/links.rs +++ b/src/output/render/links.rs @@ -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(&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, diff --git a/src/output/render/mod.rs b/src/output/render/mod.rs index ac77a132..9cc7bd3e 100644 --- a/src/output/render/mod.rs +++ b/src/output/render/mod.rs @@ -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; diff --git a/src/output/render/permissions.rs b/src/output/render/permissions.rs index 4626ad5a..452a8c45 100644 --- a/src/output/render/permissions.rs +++ b/src/output/render/permissions.rs @@ -10,8 +10,8 @@ pub trait PermissionsPlusRender { fn render(&self, colours: &C) -> TextCell; } -#[cfg(unix)] impl PermissionsPlusRender for Option { + #[cfg(unix)] fn render(&self, colours: &C) -> TextCell { match self { Some(p) => { @@ -42,13 +42,23 @@ impl PermissionsPlusRender for Option { } #[cfg(windows)] - pub fn render(&self, colours: &C) -> TextCell { - let mut chars = vec![ self.attributes.render_type(colours) ]; - chars.extend(self.attributes.render(colours)); + fn render(&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(), + } + } } } } diff --git a/src/output/table.rs b/src/output/table.rs index 04bbba41..a155c11b 100644 --- a/src/output/table.rs +++ b/src/output/table.rs @@ -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 { 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 { + Some(f::PermissionsPlus { + file_type: file.type_char(), #[cfg(windows)] attributes: file.attributes(), - xattrs + xattrs, }) } diff --git a/src/theme/mod.rs b/src/theme/mod.rs index 2bfc48e4..11c7f18e 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -201,6 +201,7 @@ impl ExtensionMappings { +#[cfg(unix)] impl render::BlocksColours for Theme { fn blocksize(&self, prefix: Option) -> 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;