Why opendal choose to trim the leading /
s.
#1039
-
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
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The most important thing is security. OpenDAL maintains an idea about And it's also important to write correct and painless code. Users don't need to consider the differences between abs_path and rel_path.
It depends on your need. If you want OpenDAL to access the whole fs, you can set root_dir to |
Beta Was this translation helpful? Give feedback.
The most important thing is security. OpenDAL maintains an idea about
root_dir
which means all operations input and output will be scoped underroot_dir
. After settings root_dir to/path/to/dir
, OpenDAL ensures that data outside of/path/to/other_dir
will not be accessed. (soft link is not supported so far).And it's also important to write correct and painless code. Users don't need to consider the differences between abs_path and rel_path.