SHA256
Changing ls_dir_rec so it ignore symlinks.
This commit is contained in:
1 parent
fb90bc3092
commit
3899af1c79
1 file changed
+20
-18
+20
-18
@@ -304,7 +304,6 @@ pub fn swapon(dev_name: &str) -> Result<(), ExecCommandError> {
|
|||||||
exec_command("swapon", &vec![dev_name])
|
exec_command("swapon", &vec![dev_name])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn fatlabel(dev: &str, label: &str) -> Result<(), ExecCommandError> {
|
pub fn fatlabel(dev: &str, label: &str) -> Result<(), ExecCommandError> {
|
||||||
//fatlabel /dev/sda1 ESP
|
//fatlabel /dev/sda1 ESP
|
||||||
exec_command("fatlabel", &vec![dev, label])
|
exec_command("fatlabel", &vec![dev, label])
|
||||||
@@ -334,27 +333,30 @@ pub fn mkswap(dev: &str) -> Result<(), ExecCommandError> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Returns list of files in directory and all subdirectories
|
/// Returns list of files in directory and all subdirectories.
|
||||||
/// Files in subdirectories listed with path related to specified dir
|
/// Files in subdirectories listed with path related to specified dir.
|
||||||
/// for example subdir1/subdir2/file
|
/// For example subdir1/subdir2/file.
|
||||||
|
/// Function do not traverse symlinks and ignores them in output.
|
||||||
///
|
///
|
||||||
pub fn ls_dir_rec(dir_part: &Path) -> Result<Vec<String>, std::io::Error> {
|
pub fn ls_dir_rec(dir_part: &Path) -> Result<Vec<String>, std::io::Error> {
|
||||||
|
///
|
||||||
fn ls_subdir_rec(root_path: &Path, prefix: String, mut res: Vec<String>) -> Result<Vec<String>, std::io::Error> {
|
/// root_path should point to dir
|
||||||
if root_path.is_dir() {
|
///
|
||||||
|
fn ls_subdir_rec(
|
||||||
|
root_path: &Path,
|
||||||
|
prefix: String,
|
||||||
|
mut res: Vec<String>,
|
||||||
|
) -> Result<Vec<String>, std::io::Error> {
|
||||||
for dir_entry in fs::read_dir(root_path)? {
|
for dir_entry in fs::read_dir(root_path)? {
|
||||||
let dir_entry = dir_entry?;
|
let dir_entry = dir_entry?;
|
||||||
let dir_entry_path = dir_entry.path();
|
let dir_entry_ft = dir_entry.file_type()?;
|
||||||
let next_prefix = format!("{}/{}", prefix, dir_entry.file_name().to_string_lossy());
|
let next_prefix = format!("{}/{}", prefix, dir_entry.file_name().to_string_lossy());
|
||||||
if dir_entry_path.is_dir() {
|
if dir_entry_ft.is_dir() {
|
||||||
|
res = ls_subdir_rec(&dir_entry.path(), next_prefix, res)?;
|
||||||
res = ls_subdir_rec(&dir_entry_path, next_prefix, res)?;
|
} else if dir_entry_ft.is_file() {
|
||||||
}
|
|
||||||
else {
|
|
||||||
res.push(next_prefix);
|
res.push(next_prefix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,11 +366,11 @@ pub fn ls_dir_rec(dir_part: &Path) -> Result<Vec<String>, std::io::Error> {
|
|||||||
if dir_part.is_dir() {
|
if dir_part.is_dir() {
|
||||||
for d_entry in fs::read_dir(dir_part)? {
|
for d_entry in fs::read_dir(dir_part)? {
|
||||||
let d_entry = d_entry?;
|
let d_entry = d_entry?;
|
||||||
let d_entry_path = d_entry.path();
|
let d_entry_ft = d_entry.file_type()?;
|
||||||
let d_entry_name = d_entry.file_name().to_string_lossy().to_string();
|
let d_entry_name = d_entry.file_name().to_string_lossy().to_string();
|
||||||
if d_entry_path.is_dir() {
|
if d_entry_ft.is_dir() {
|
||||||
res = ls_subdir_rec(&d_entry_path, d_entry_name, res)?;
|
res = ls_subdir_rec(&d_entry.path(), d_entry_name, res)?;
|
||||||
} else {
|
} else if d_entry_ft.is_file() {
|
||||||
// Add file to list
|
// Add file to list
|
||||||
res.push(d_entry_name);
|
res.push(d_entry_name);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user