MCPcopy Create free account
hub / github.com/apache/datafusion / url_from_filesystem_path

Function url_from_filesystem_path

datafusion/datasource/src/url.rs:437–462  ·  view source on GitHub ↗
(s: &str)

Source from the content-addressed store, hash-verified

435/// Creates a file URL from a potentially relative filesystem path
436#[cfg(not(target_arch = "wasm32"))]
437fn url_from_filesystem_path(s: &str) -> Option<Url> {
438 let path = std::path::Path::new(s);
439 let is_dir = match path.exists() {
440 true => path.is_dir(),
441 // Fallback to inferring from trailing separator
442 false => std::path::is_separator(s.chars().last()?),
443 };
444
445 let from_absolute_path = |p| {
446 let first = match is_dir {
447 true => Url::from_directory_path(p).ok(),
448 false => Url::from_file_path(p).ok(),
449 }?;
450
451 // By default from_*_path preserve relative path segments
452 // We therefore parse the URL again to resolve these
453 Url::parse(first.as_str()).ok()
454 };
455
456 if path.is_absolute() {
457 return from_absolute_path(path);
458 }
459
460 let absolute = std::env::current_dir().ok()?.join(path);
461 from_absolute_path(&absolute)
462}
463
464impl AsRef<str> for ListingTableUrl {
465 fn as_ref(&self) -> &str {

Callers 1

parse_pathMethod · 0.85

Calls 5

newFunction · 0.85
existsMethod · 0.80
lastMethod · 0.80
as_strMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…