aboutsummaryrefslogtreecommitdiffstats
path: root/src/file_utils.rs
diff options
context:
space:
mode:
authorcyqsimon <28627918+cyqsimon@users.noreply.github.com>2023-03-22 23:39:00 +0000
committercyqsimon <28627918+cyqsimon@users.noreply.github.com>2023-07-10 05:51:28 +0000
commit03915c3d33a6a053a1455a2ba48ad57e0477365a (patch)
tree42d4d1e37965feb342c8a30f299ff9e740b55c56 /src/file_utils.rs
parentCreate shared file utiity module (diff)
downloadminiserve-03915c3d33a6a053a1455a2ba48ad57e0477365a.tar.gz
miniserve-03915c3d33a6a053a1455a2ba48ad57e0477365a.zip
Make file util functions generic
Diffstat (limited to '')
-rw-r--r--src/file_utils.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/file_utils.rs b/src/file_utils.rs
index fdd68ba..ba976de 100644
--- a/src/file_utils.rs
+++ b/src/file_utils.rs
@@ -4,10 +4,10 @@ use std::path::{Component, Path, PathBuf};
/// and optionally prevent traversing hidden directories.
///
/// See the unit tests tests::test_sanitize_path* for examples
-pub fn sanitize_path(path: &Path, traverse_hidden: bool) -> Option<PathBuf> {
+pub fn sanitize_path(path: impl AsRef<Path>, traverse_hidden: bool) -> Option<PathBuf> {
let mut buf = PathBuf::new();
- for comp in path.components() {
+ for comp in path.as_ref().components() {
match comp {
Component::Normal(name) => buf.push(name),
Component::ParentDir => {
@@ -30,9 +30,9 @@ pub fn sanitize_path(path: &Path, traverse_hidden: bool) -> Option<PathBuf> {
}
/// Returns if a path goes through a symbolic link
-pub fn contains_symlink(path: &PathBuf) -> bool {
+pub fn contains_symlink(path: impl AsRef<Path>) -> bool {
let mut joined_path = PathBuf::new();
- for path_slice in path {
+ for path_slice in path.as_ref().iter() {
joined_path = joined_path.join(path_slice);
if !joined_path.exists() {
// On Windows, `\\?\` won't exist even though it's the root