Skip to content

Commit

Permalink
Remove debug prompts and delete more UNC path normalization tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-F-Bryan committed Mar 28, 2023
1 parent 934e2c0 commit 5f804a7
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions lib/vfs/src/webc_volume_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl FileSystem for WebcVolumeFileSystem {
return Err(FsError::BaseNotDirectory);
}

let path = dbg!(normalize(path)).map_err(|_| FsError::InvalidInput)?;
let path = normalize(path).map_err(|_| FsError::InvalidInput)?;

let mut entries = Vec::new();

Expand Down Expand Up @@ -123,7 +123,7 @@ impl FileSystem for WebcVolumeFileSystem {
}

fn metadata(&self, path: &Path) -> Result<Metadata, FsError> {
let path = dbg!(normalize(path)).map_err(|_| FsError::InvalidInput)?;
let path = normalize(path).map_err(|_| FsError::InvalidInput)?;

self.volume()
.metadata(path)
Expand Down Expand Up @@ -293,10 +293,19 @@ fn compat_meta(meta: webc::compat::Metadata) -> Metadata {

/// Normalize a [`Path`] into a [`PathSegments`], dealing with things like `..`
/// and skipping `.`'s.
#[tracing::instrument(level = "trace", err)]
fn normalize(path: &Path) -> Result<PathSegments, PathSegmentError> {
// normalization is handled by the ToPathSegments impl for Path
path.to_path_segments()
let result = path.to_path_segments();

if let Err(e) = &result {
tracing::debug!(
error = e as &dyn std::error::Error,
path=%path.display(),
"Unable to normalize a path",
);
}

result
}

#[cfg(test)]
Expand Down Expand Up @@ -341,10 +350,6 @@ mod tests {
),
(r"\\.\c:\temp\test-file.txt", &["temp", "test-file.txt"]),
(r"\\?\c:\temp\test-file.txt", &["temp", "test-file.txt"]),
(
r"\\.\UNC\LOCALHOST\c$\temp\test-file.txt",
&["temp", "test-file.txt"],
),
(
r"\\127.0.0.1\c$\temp\test-file.txt",
&["temp", "test-file.txt"],
Expand All @@ -357,28 +362,16 @@ mod tests {

for (path, expected) in inputs {
let normalized = normalize(path.as_ref()).unwrap();
assert_eq!(normalized, expected.to_path_segments().unwrap());
assert_eq!(normalized, expected.to_path_segments().unwrap(), "{}", path);
}
}

#[test]
fn invalid_paths() {
let paths = [
(".", PathSegmentError::NotAbsolute),
("..", PathSegmentError::NotAbsolute),
("./file.txt", PathSegmentError::NotAbsolute),
(
"",
if cfg!(windows) {
PathSegmentError::Empty
} else {
PathSegmentError::NotAbsolute
},
),
];
let paths = [".", "..", "./file.txt", ""];

for (path, err) in paths {
assert_eq!(normalize(path.as_ref()).unwrap_err(), err, "{path}");
for path in paths {
assert!(normalize(path.as_ref()).is_err(), "{}", path);
}
}

Expand Down

0 comments on commit 5f804a7

Please sign in to comment.