@@ -34,9 +34,10 @@ pub trait Task {
3434fn is_program_in_path ( program : & str ) -> bool {
3535 if let Ok ( path) = env:: var ( "PATH" ) {
3636 for p in path. split ( ":" ) {
37+ println ! ( "p={}" , p) ;
3738 let p_str = format ! ( "{}/{}" , p, program) ;
3839 if fs:: metadata ( & p_str) . is_ok ( ) {
39- println ! ( "Trying: {}" , p_str) ;
40+ println ! ( "p_str= {}" , p_str) ;
4041 return true ;
4142 }
4243 }
@@ -80,8 +81,12 @@ pub fn cmd(dir: &str, cmd: &str, args: &[&str]) -> io::Result<()> {
8081fn is_directory ( filepath : & str ) -> io:: Result < bool > {
8182 use std:: path:: Path ;
8283 let path = Path :: new ( filepath) ;
84+ println ! ( "path_to_string(path)={:?}" , path_to_string( path) . unwrap( ) ) ;
8385 match fs:: metadata ( path) {
84- Ok ( metadata) => Ok ( metadata. is_dir ( ) ) ,
86+ Ok ( metadata) => {
87+ println ! ( "path_to_string(path)={:?}" , path_to_string( path) ) ;
88+ Ok ( metadata. is_dir ( ) )
89+ }
8590 Err ( e) => Err ( e) ,
8691 }
8792}
@@ -91,70 +96,28 @@ fn path_to_string(path: &Path) -> Result<String, std::ffi::OsString> {
9196 path. as_os_str ( ) . to_os_string ( ) . into_string ( )
9297}
9398
94- /// Purges a location on disk, similar to `rm -rf`.
9599pub fn filepath ( parent : & str , child : & str ) -> io:: Result < ( ) > {
96- let dir_path = String :: from ( format ! ( "{}/{}" , parent, child) ) ;
97- println ! ( "{}" , dir_path) ;
98-
99- if let dir = is_directory ( & dir_path. clone ( ) ) {
100- println ! ( "'{}' is a directory." , dir_path) ;
101- println ! ( "{:?}" , dir) ;
102- } else if let dir = !is_directory ( & dir_path. clone ( ) ) . expect ( "" ) {
103- println ! (
104- "'{}' is not a directory (or the path doesn't exist)." ,
105- dir_path
106- ) ;
107-
108- println ! ( "{}" , dir) ;
109- } else {
110- }
111-
112- // check for errors that we're ok with
113- //if let Err(err) = fs::remove_dir_all(dir_path) {
114- // // if already gone, happy days are upon us
115- // if err.kind() == ErrorKind::NotFound {
116- // return Ok(());
117- // }
118- // // if there's a permission error, we don't care
119- // if err.kind() == ErrorKind::PermissionDenied {
120- // return Ok(());
121- // }
122- // if err.kind() == ErrorKind::Other {
123- // let file_path = format!("{}/{}", parent, child);
124- // println!("{}", file_path);
125- // // check for errors that we're ok with
126- // if let Err(err) = fs::remove_file(file_path) {
127- // // if already gone, happy days are upon us
128- // if err.kind() == ErrorKind::NotFound {
129- // return Ok(());
130- // }
131-
132- // // if there's a permission error, we don't care
133- // if err.kind() == ErrorKind::PermissionDenied {
134- // return Ok(());
135- // }
136- // if err.kind() == ErrorKind::Other {
137- // return Ok(());
138- // }
139-
140- // // others, bad!
141- // // return Err(err);
142- // println!("{:?}", Some(err));
143- // }
144-
145- // return Ok(());
146- // }
147-
148- // // others, bad!
149- // // return Err(err);
150- // println!("{:?}", Some(err));
151- //}
100+ let dir_path = format ! ( "{}/{}" , parent, child) ;
101+ println ! ( "dir_path={}" , dir_path) ;
152102
103+ if let Ok ( dir) = is_directory ( & dir_path. clone ( ) ) {
104+ println ! ( "dir={}" , dir) ;
105+ match dir {
106+ true => {
107+ println ! ( "'{}' is a directory." , dir) ;
108+ }
109+ false => {
110+ println ! ( "{:?} is NOT a directory!" , dir) ;
111+ }
112+ }
113+ } ;
114+ //let dir = !is_directory(&dir_path.clone()).expect("");
153115 Ok ( ( ) )
154116}
155117
156118/// Purges a location on disk, similar to `rm -rf`.
157119pub fn del ( parent : & str , child : & str ) -> io:: Result < ( ) > {
120+ let _ = filepath ( parent, child) ;
158121 let dir_path = format ! ( "{}/{}" , parent, child) ;
159122 println ! ( "{}" , dir_path) ;
160123
0 commit comments