@@ -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+
467475fn 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