@@ -257,6 +257,11 @@ function get_entry_name(e) {
257
257
return e . name ;
258
258
}
259
259
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
+
260
265
/**
261
266
* @param {string } name
262
267
* @returns {fs.Dirent }
@@ -668,14 +673,20 @@ class NamespaceFS {
668
673
}
669
674
const marker_dir = key_marker . slice ( 0 , dir_key . length ) ;
670
675
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 ( '/' , ' ' ) ;
671
681
// 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 ) {
673
683
// dbg.log0(`marker is after dir so no keys in this dir can apply: dir_key=${dir_key} marker_dir=${marker_dir}`);
674
684
return ;
675
685
}
676
686
// when the dir portion of the marker is completely below the current dir
677
687
// 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 } ) ;
679
690
// dbg.log0(`process_dir: dir_key=${dir_key} prefix_ent=${prefix_ent} marker_curr=${marker_curr}`);
680
691
/**
681
692
* @typedef {{
@@ -690,7 +701,7 @@ class NamespaceFS {
690
701
// they are in order
691
702
if ( results . length && r . key < results [ results . length - 1 ] . key &&
692
703
! this . _is_hidden_version_path ( r . key ) ) {
693
- pos = _ . sortedLastIndexBy ( results , r , a => a . key ) ;
704
+ pos = _ . sortedLastIndexBy ( results , r , get_entry_for_sorting ) ;
694
705
} else {
695
706
pos = results . length ;
696
707
}
@@ -720,7 +731,7 @@ class NamespaceFS {
720
731
const process_entry = async ent => {
721
732
// dbg.log0('process_entry', dir_key, ent.name);
722
733
if ( ( ! ent . name . startsWith ( prefix_ent ) ||
723
- ent . name < marker_curr ||
734
+ ent . name < marker_sorting_entry ||
724
735
ent . name === this . get_bucket_tmpdir_name ( ) ||
725
736
ent . name === config . NSFS_FOLDER_OBJECT_NAME ) ||
726
737
this . _is_hidden_version_path ( ent . name ) ) {
@@ -763,7 +774,7 @@ class NamespaceFS {
763
774
// insert dir object to objects list if its key is lexicographicly bigger than the key marker &&
764
775
// no delimiter OR prefix is the current directory entry
765
776
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 ) ) {
767
778
const r = { key : dir_key , common_prefix : false } ;
768
779
await insert_entry_to_results_arr ( r ) ;
769
780
}
@@ -788,7 +799,7 @@ class NamespaceFS {
788
799
} else {
789
800
marker_index = _ . sortedLastIndexBy (
790
801
sorted_entries ,
791
- make_named_dirent ( marker_curr ) ,
802
+ make_named_dirent ( marker_sorting_entry ) ,
792
803
get_entry_name
793
804
) ;
794
805
}
0 commit comments