Skip to content

Commit

Permalink
Make it work with macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronaldo Ferreira authored and nachoparker committed May 10, 2018
1 parent 60b35ec commit be55e95
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dutree"
version = "0.2.6"
version = "0.2.7"
authors = ["nacho <nacho@ownyourbits.com>"]
description = "Command line tool to analyze disk usage"
repository = "https://github.com/nachoparker/dutree"
Expand Down
11 changes: 10 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ use regex::Regex;
use std::io;
use std::path::{Path, PathBuf};
use std::fs;
#[cfg(target_os = "linux")]
use std::os::linux::fs::MetadataExt;
#[cfg(target_os = "macos")]
use std::os::unix::fs::MetadataExt;
use std::env;
use std::collections::HashMap;

const VERSTR : &str = "v0.2.6";
const VERSTR : &str = "v0.2.7";
const DEF_WIDTH : u16 = 80;

pub enum XResult<T,S> {
Expand Down Expand Up @@ -227,7 +230,10 @@ fn try_read_dir( path : &Path ) -> Option<fs::ReadDir> {
fn try_bytes_from_path( path : &Path, usage_flag : bool ) -> u64 {

match path.symlink_metadata() {
#[cfg(target_os = "linux")]
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) => {
print_io_error( path, err );
0
Expand Down Expand Up @@ -480,7 +486,10 @@ fn color_from_path<'a>( path : &Path, color_dict : &'a HashMap<String, String> )
}
let metadata = path.symlink_metadata();
if metadata.is_ok() {
#[cfg(target_os = "linux")]
let mode = metadata.unwrap().st_mode();
#[cfg(target_os = "macos")]
let mode = metadata.unwrap().mode();
if path.is_dir() {
if mode & 0o002 != 0 { // dir other writable
if let Some( col ) = color_dict.get( &"ow".to_string() ) {
Expand Down

0 comments on commit be55e95

Please sign in to comment.