Skip to content

Commit 3ddacd2

Browse files
author
kontinuation
committed
fix(rust/sedona-raster-gdal,c/sedona-gdal): avoid VSI separator symbol
1 parent 2508f7c commit 3ddacd2

5 files changed

Lines changed: 17 additions & 27 deletions

File tree

c/sedona-gdal/src/dyn_load.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ fn load_all_symbols(lib: &Library, api: &mut SedonaGdalApi) -> Result<(), GdalIn
157157
load_fn!(lib, api, VSIFileFromMemBuffer);
158158
load_fn!(lib, api, VSIFCloseL);
159159
load_fn!(lib, api, VSIUnlink);
160-
load_fn!(lib, api, VSIGetDirectorySeparator);
161160
load_fn!(lib, api, VSIOpenDir);
162161
load_fn!(lib, api, VSIGetNextDirEntry);
163162
load_fn!(lib, api, VSICloseDir);

c/sedona-gdal/src/gdal.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,6 @@ impl Gdal {
182182
crate::vsi::open_dir(self.api, path, recurse_depth, options)
183183
}
184184

185-
/// Return the directory separator used by GDAL for a given VSI path.
186-
/// See also [`vsi::get_directory_separator`].
187-
pub fn vsi_directory_separator(&self, path: &str) -> Result<String> {
188-
crate::vsi::get_directory_separator(self.api, path)
189-
}
190-
191185
// -- Raster operations ---------------------------------------------------
192186

193187
/// Create a bare in-memory MEM dataset with GDAL-owned bands.

c/sedona-gdal/src/gdal_dyn_bindgen.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,6 @@ pub(crate) struct SedonaGdalApi {
477477
>,
478478
pub VSIFCloseL: Option<unsafe extern "C" fn(fp: VSILFILE) -> c_int>,
479479
pub VSIUnlink: Option<unsafe extern "C" fn(pszFilename: *const c_char) -> c_int>,
480-
pub VSIGetDirectorySeparator:
481-
Option<unsafe extern "C" fn(pszPath: *const c_char) -> *const c_char>,
482480
pub VSIOpenDir: Option<
483481
unsafe extern "C" fn(
484482
pszPath: *const c_char,

c/sedona-gdal/src/vsi.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -375,17 +375,3 @@ pub fn open_dir(
375375
}
376376
Ok(VsiDir { api, handle })
377377
}
378-
379-
pub fn get_directory_separator(
380-
api: &'static crate::gdal_api::GdalApi,
381-
path: &str,
382-
) -> crate::errors::Result<String> {
383-
let c_path = std::ffi::CString::new(path)?;
384-
let separator_ptr = unsafe { (api.inner.VSIGetDirectorySeparator.unwrap())(c_path.as_ptr()) };
385-
if separator_ptr.is_null() {
386-
return Err(api.last_null_pointer_err("VSIGetDirectorySeparator"));
387-
}
388-
Ok(unsafe { std::ffi::CStr::from_ptr(separator_ptr) }
389-
.to_string_lossy()
390-
.into_owned())
391-
}

rust/sedona-raster-gdal/src/rs_geotiff_tiles.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,7 @@ fn list_geotiffs(path: &str, recursive: bool) -> Result<Vec<String>> {
428428

429429
let recurse_depth = if recursive { -1 } else { 0 };
430430
let list_result = with_gdal(|gdal| {
431-
let separator = gdal
432-
.vsi_directory_separator(&normalized_path)
433-
.map_err(convert_gdal_err)?;
431+
let separator = directory_separator_for_path(&normalized_path);
434432
let mut dir = gdal
435433
.open_vsi_dir(&normalized_path, recurse_depth, None)
436434
.map_err(convert_gdal_err)?;
@@ -445,7 +443,7 @@ fn list_geotiffs(path: &str, recursive: bool) -> Result<Vec<String>> {
445443
continue;
446444
}
447445

448-
let child_path = join_vsi_path(&normalized_path, &separator, &entry.name);
446+
let child_path = join_vsi_path(&normalized_path, separator, &entry.name);
449447
if is_geotiff_path_str(&child_path) {
450448
out.push(child_path);
451449
}
@@ -464,6 +462,16 @@ fn list_geotiffs(path: &str, recursive: bool) -> Result<Vec<String>> {
464462
}
465463
}
466464

465+
fn directory_separator_for_path(path: &str) -> &'static str {
466+
if path.starts_with("/vsi") || path.contains("://") {
467+
"/"
468+
} else if path.contains('\\') {
469+
"\\"
470+
} else {
471+
"/"
472+
}
473+
}
474+
467475
fn join_vsi_path(base: &str, separator: &str, child_name: &str) -> String {
468476
if base.ends_with(separator) {
469477
format!("{base}{child_name}")
@@ -581,6 +589,11 @@ mod tests {
581589
assert!(is_geotiff_path_str("https://host/data.tif?token=abc#f"));
582590
assert!(!is_geotiff_path_str("/tmp/a.txt"));
583591
assert!(!is_geotiff_path_str("/tmp/a"));
592+
593+
assert_eq!(directory_separator_for_path("/vsis3/bucket/prefix"), "/");
594+
assert_eq!(directory_separator_for_path("https://host/data.tif"), "/");
595+
assert_eq!(directory_separator_for_path(r"C:\data\dir"), r"\");
596+
assert_eq!(directory_separator_for_path("/tmp/data"), "/");
584597
}
585598

586599
#[tokio::test]

0 commit comments

Comments
 (0)