1
0
Fork 0
mirror of https://github.com/nachoparker/dutree synced 2024-05-12 23:56:08 +02:00

Make it work with macOS

This commit is contained in:
Ronaldo Ferreira 2018-04-17 15:29:30 +02:00 committed by Ignacio Nunez
parent 60b35ec74b
commit be55e95636
2 changed files with 11 additions and 2 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "dutree" name = "dutree"
version = "0.2.6" version = "0.2.7"
authors = ["nacho <nacho@ownyourbits.com>"] authors = ["nacho <nacho@ownyourbits.com>"]
description = "Command line tool to analyze disk usage" description = "Command line tool to analyze disk usage"
repository = "https://github.com/nachoparker/dutree" repository = "https://github.com/nachoparker/dutree"

View File

@ -52,11 +52,14 @@ use regex::Regex;
use std::io; use std::io;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::fs; use std::fs;
#[cfg(target_os = "linux")]
use std::os::linux::fs::MetadataExt; use std::os::linux::fs::MetadataExt;
#[cfg(target_os = "macos")]
use std::os::unix::fs::MetadataExt;
use std::env; use std::env;
use std::collections::HashMap; use std::collections::HashMap;
const VERSTR : &str = "v0.2.6"; const VERSTR : &str = "v0.2.7";
const DEF_WIDTH : u16 = 80; const DEF_WIDTH : u16 = 80;
pub enum XResult<T,S> { pub enum XResult<T,S> {
@ -227,7 +230,10 @@ fn try_read_dir( path : &Path ) -> Option<fs::ReadDir> {
fn try_bytes_from_path( path : &Path, usage_flag : bool ) -> u64 { fn try_bytes_from_path( path : &Path, usage_flag : bool ) -> u64 {
match path.symlink_metadata() { match path.symlink_metadata() {
#[cfg(target_os = "linux")]
Ok(metadata) => if usage_flag { metadata.st_blocks()*512 } else { metadata.st_size() }, Ok(metadata) => if usage_flag { metadata.st_blocks()*512 } else { metadata.st_size() },
#[cfg(target_os = "macos")]
Ok(metadata) => if usage_flag { metadata.blocks()*512 } else { metadata.size() },
Err(err) => { Err(err) => {
print_io_error( path, err ); print_io_error( path, err );
0 0
@ -480,7 +486,10 @@ fn color_from_path<'a>( path : &Path, color_dict : &'a HashMap<String, String> )
} }
let metadata = path.symlink_metadata(); let metadata = path.symlink_metadata();
if metadata.is_ok() { if metadata.is_ok() {
#[cfg(target_os = "linux")]
let mode = metadata.unwrap().st_mode(); let mode = metadata.unwrap().st_mode();
#[cfg(target_os = "macos")]
let mode = metadata.unwrap().mode();
if path.is_dir() { if path.is_dir() {
if mode & 0o002 != 0 { // dir other writable if mode & 0o002 != 0 { // dir other writable
if let Some( col ) = color_dict.get( &"ow".to_string() ) { if let Some( col ) = color_dict.get( &"ow".to_string() ) {