@@ -257,6 +257,11 @@ function get_entry_name(e) {
257257 return e . name ;
258258}
259259
260+ function get_entry_for_sorting ( e ) {
261+ const check = e . key . includes ( '.' ) ? e . key . slice ( e . key . indexOf ( "." ) ) . includes ( '/' ) : false ;
262+ return check ? e . key . slice ( '/' ) [ 0 ] : e . key ;
263+ }
264+
260265/**
261266 * @param {string } name
262267 * @returns {fs.Dirent }
@@ -668,14 +673,20 @@ class NamespaceFS {
668673 }
669674 const marker_dir = key_marker . slice ( 0 , dir_key . length ) ;
670675 const marker_ent = key_marker . slice ( dir_key . length ) ;
676+ // dir_key and marker_dir comparison will fail when there are folder with structure slimier to
677+ // "dir_prfix.12345/" and "dir_prfix.12345.old/" because "/" considered greater than "." to fix this
678+ // all the backslash is replaced with space. This updated marker and dir_key used only for comparison.
679+ const updated_marker_dir = marker_dir . replaceAll ( '/' , ' ' ) ;
680+ const updated_dir_key = dir_key . replaceAll ( '/' , ' ' ) ;
671681 // marker is after dir so no keys in this dir can apply
672- if ( dir_key < marker_dir ) {
682+ if ( updated_dir_key < updated_marker_dir ) {
673683 // dbg.log0(`marker is after dir so no keys in this dir can apply: dir_key=${dir_key} marker_dir=${marker_dir}`);
674684 return ;
675685 }
676686 // when the dir portion of the marker is completely below the current dir
677687 // then every key in this dir satisfies the marker and marker_ent should not be used.
678- const marker_curr = ( marker_dir < dir_key ) ? '' : marker_ent ;
688+ const marker_curr = ( updated_marker_dir < updated_dir_key ) ? '' : marker_ent ;
689+ const marker_sorting_entry = get_entry_for_sorting ( { key : marker_curr } ) ;
679690 // dbg.log0(`process_dir: dir_key=${dir_key} prefix_ent=${prefix_ent} marker_curr=${marker_curr}`);
680691 /**
681692 * @typedef {{
@@ -690,7 +701,7 @@ class NamespaceFS {
690701 // they are in order
691702 if ( results . length && r . key < results [ results . length - 1 ] . key &&
692703 ! this . _is_hidden_version_path ( r . key ) ) {
693- pos = _ . sortedLastIndexBy ( results , r , a => a . key ) ;
704+ pos = _ . sortedLastIndexBy ( results , r , get_entry_for_sorting ) ;
694705 } else {
695706 pos = results . length ;
696707 }
@@ -720,7 +731,7 @@ class NamespaceFS {
720731 const process_entry = async ent => {
721732 // dbg.log0('process_entry', dir_key, ent.name);
722733 if ( ( ! ent . name . startsWith ( prefix_ent ) ||
723- ent . name < marker_curr ||
734+ ent . name < marker_sorting_entry ||
724735 ent . name === this . get_bucket_tmpdir_name ( ) ||
725736 ent . name === config . NSFS_FOLDER_OBJECT_NAME ) ||
726737 this . _is_hidden_version_path ( ent . name ) ) {
@@ -763,7 +774,7 @@ class NamespaceFS {
763774 // insert dir object to objects list if its key is lexicographicly bigger than the key marker &&
764775 // no delimiter OR prefix is the current directory entry
765776 const is_dir_content = cached_dir . stat . xattr && cached_dir . stat . xattr [ XATTR_DIR_CONTENT ] ;
766- if ( is_dir_content && dir_key > key_marker && ( ! delimiter || dir_key === prefix ) ) {
777+ if ( is_dir_content && updated_dir_key > updated_marker_dir && ( ! delimiter || dir_key === prefix ) ) {
767778 const r = { key : dir_key , common_prefix : false } ;
768779 await insert_entry_to_results_arr ( r ) ;
769780 }
@@ -788,7 +799,7 @@ class NamespaceFS {
788799 } else {
789800 marker_index = _ . sortedLastIndexBy (
790801 sorted_entries ,
791- make_named_dirent ( marker_curr ) ,
802+ make_named_dirent ( marker_sorting_entry ) ,
792803 get_entry_name
793804 ) ;
794805 }
0 commit comments