mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-10-28 00:10:50 +08:00
refactor: 删除部分多余的代码和注释
This commit is contained in:
23
src/utils/fs.rs
Normal file
23
src/utils/fs.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
//! Small filesystem helpers.
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
/// Read a UTF-8 file and trim surrounding whitespace.
|
||||
pub fn read_trimmed(path: &Path) -> Option<String> {
|
||||
std::fs::read_to_string(path)
|
||||
.ok()
|
||||
.map(|value| value.trim().to_string())
|
||||
}
|
||||
|
||||
/// Sorted list of directory entry names (lossy exclusion on non-UTF8).
|
||||
pub fn list_dir_names(path: &Path) -> Vec<String> {
|
||||
let mut names = std::fs::read_dir(path)
|
||||
.ok()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.flatten()
|
||||
.filter_map(|entry| entry.file_name().into_string().ok())
|
||||
.collect::<Vec<_>>();
|
||||
names.sort();
|
||||
names
|
||||
}
|
||||
Reference in New Issue
Block a user