use super::super::Error;
use std::path::{Component, Path, PathBuf};
pub fn find_mountpoint_pre_canonicalized(path: &Path) -> Result<&Path, Error> {
for component in path.components() {
if let Component::Prefix(prefix) = component {
return Ok(Path::new(prefix.as_os_str()));
}
}
Err(Error::from("Couldn't find prefix on path.".to_owned()))
}
pub fn find_mountpoint(path: &Path) -> Result<PathBuf, Error> {
let canonicalized = path.canonicalize()?;
let found = find_mountpoint_pre_canonicalized(canonicalized.as_path())?;
Ok(found.to_path_buf())
}