This repository has been archived by the owner on Nov 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from kbknapp/dev
fix(Symlinks): adds ability to optionally follow symlinks while counting
- Loading branch information
Showing
5 changed files
with
100 additions
and
76 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,56 @@ | ||
use std::fs; | ||
use std::fs::metadata; | ||
use std::io::Result; | ||
use std::path::PathBuf; | ||
|
||
use glob; | ||
|
||
pub fn get_all_files<'a>(path: &'a str, exclude: &Vec<&'a str>) -> Vec<PathBuf> { | ||
pub fn get_all_files<'a>(v: &mut Vec<PathBuf>, path: &PathBuf, exclude: &Vec<PathBuf>, follow_links: bool) { | ||
debugln!("executing; get_all_files; path={:?}; exclude={:?};", path, exclude); | ||
let mut files = vec![]; | ||
if exclude.contains(path) { | ||
return | ||
} | ||
|
||
debugln!("Getting metadata"); | ||
if let Ok(result) = metadata(&path) { | ||
if let Ok(result) = get_metadata(&path, follow_links) { | ||
debugln!("Found"); | ||
if result.is_dir() { | ||
debugln!("It's a dir"); | ||
let dir = fs::read_dir(&path).unwrap(); | ||
'file: for entry in dir { | ||
for entry in dir { | ||
let entry = entry.unwrap(); | ||
let file_path = entry.path(); | ||
let file_str = file_path.to_str().expect("file_path isn't a valid str"); | ||
let file_string = file_str.to_owned(); | ||
let path_metadata = metadata(&file_string).unwrap(); | ||
|
||
for ignored in exclude { | ||
debugln!("iter; ignored={:?}", ignored); | ||
if file_str.contains(ignored) { | ||
debugln!("iter; ignored={:?}", ignored); | ||
continue 'file; | ||
} | ||
} | ||
if path_metadata.is_dir() { | ||
for file in get_all_files(&*file_string, &exclude) { | ||
files.push(file); | ||
} | ||
} else if path_metadata.is_file() { | ||
files.push(PathBuf::from(file_str)); | ||
} | ||
get_all_files(v, &file_path.to_path_buf(), &exclude, follow_links); | ||
} | ||
} else { | ||
debugln!("It's a file"); | ||
if !exclude.contains(&path) { | ||
debugln!("It's not excluded"); | ||
files.push(PathBuf::from(path)); | ||
} else { | ||
debugln!("It's excluded"); | ||
} | ||
v.push(path.clone()); | ||
} | ||
} else { | ||
for path_buf in glob::glob(&path).ok().expect("failed to get files from glob") { | ||
let file_path = path_buf.unwrap(); | ||
files.push(file_path); | ||
for path_buf in glob::glob(path.to_str().unwrap_or("")).ok().expect("failed to get files from glob") { | ||
if let Ok(file_path) = path_buf { | ||
if let Ok(result) = get_metadata(&file_path, follow_links) { | ||
if result.is_dir() { | ||
debugln!("It's a dir"); | ||
let dir = fs::read_dir(&path).unwrap(); | ||
for entry in dir { | ||
let entry = entry.unwrap(); | ||
let file_path = entry.path(); | ||
get_all_files(v, &file_path.to_path_buf(), &exclude, follow_links); | ||
} | ||
} else { | ||
debugln!("It's a file"); | ||
v.push(path.clone()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
files | ||
fn get_metadata(path: &PathBuf, follow_links: bool) -> Result<fs::Metadata> { | ||
if follow_links { | ||
fs::metadata(path) | ||
} else { | ||
fs::symlink_metadata(path) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters