-
Notifications
You must be signed in to change notification settings - Fork 703
Closed
Description
I'm wondering why opendal choose to normalize the path by tirmming the leading '/'. (What's the purpose?)
If I want to access a absolute path on my own local filesystem (for example: '/home/rinchannow/xxx.parquet'), it means I have to set the operator root to '/'?.
Why not use the absolute path directly?
OpenDAL Source codes:
/// Make sure all operation are constructed by normalized path:
///
/// - Path endswith `/` means it's a dir path.
/// - Otherwise, it's a file path.
///
/// # Normalize Rules
///
/// - All whitespace will be trimmed: ` abc/def ` => `abc/def`
/// - All leading / will be trimmed: `///abc` => `abc`
/// - Internal // will be replaced by /: `abc///def` => `abc/def`
/// - Empty path will be `/`: `` => `/`
pub fn normalize_path(path: &str) -> String {
// - all whitespace has been trimmed.
// - all leading `/` has been trimmed.
let path = path.trim().trim_start_matches('/');
// Fast line for empty path.
if path.is_empty() {
return "/".to_string();
}
let has_trailing = path.ends_with('/');
let mut p = path
.split('/')
.filter(|v| !v.is_empty())
.collect::<Vec<&str>>()
.join("/");
// Append trailing back if input path is endswith `/`.
if has_trailing {
p.push('/');
}
p
}Metadata
Metadata
Assignees
Labels
No labels