@@ -37,34 +37,50 @@ export class SAFDocumentFile implements FileObject {
3737 }
3838
3939 //if this fails then...
40- async isMyChild ( fileObject : FileObject ) : Promise < boolean > {
41- if ( ! ( fileObject instanceof SAFDocumentFile ) ) {
42- return false ;
43- }
44- if ( ! ( await this . isDirectory ( ) ) ) {
45- return false ;
46- }
40+ async isMyChild ( fileObject : FileObject ) : Promise < boolean > {
41+ console . log ( `[isMyChild] Checking if` , fileObject , `is a child of` , this ) ;
4742
48- let current : FileObject | null = fileObject ;
43+ if ( ! ( fileObject instanceof SAFDocumentFile ) ) {
44+ console . log ( `[isMyChild] Not an SAFDocumentFile` ) ;
45+ return false ;
46+ }
4947
50- while ( current !== null ) {
51- const parent : FileObject | null = await current . getParentFile ( ) ;
52- if ( parent === null ) {
53- return false ; // Reached root without finding this
54- }
48+ const isDir = await this . isDirectory ( ) ;
49+ if ( ! isDir ) {
50+ console . log ( `[isMyChild] This file is not a directory` ) ;
51+ return false ;
52+ }
5553
56- const parentUri = await parent . toUri ( ) ;
57- if ( parentUri === this . uri ) {
58- return true ; // Found a match
59- }
54+ let current : FileObject | null = fileObject ;
6055
61- current = parent ;
62- }
56+ while ( current !== null ) {
57+ console . log ( `[isMyChild] Checking parent of` , current ) ;
58+
59+ const parent : FileObject | null = await current . getParentFile ( ) ;
60+ if ( parent === null ) {
61+ console . log ( `[isMyChild] Reached root without finding match` ) ;
62+ return false ;
63+ }
64+
65+ const parentUri = ( await parent . toUri ( ) ) ?. replace ( / \/ + $ / , "" ) ;
66+ const thisUri = this . uri ?. replace ( / \/ + $ / , "" ) ;
67+
68+ console . log ( `[isMyChild] parentUri=${ parentUri } , thisUri=${ thisUri } ` ) ;
69+
70+ if ( parentUri === thisUri ) {
71+ console . log ( `[isMyChild] Match found!` ) ;
72+ return true ;
73+ }
74+
75+ current = parent ;
76+ }
77+
78+ console . log ( `[isMyChild] No match found after traversal` ) ;
79+ return false ;
80+ }
6381
64- return false ;
65- }
6682
67- async canRead ( ) : Promise < boolean > {
83+ async canRead ( ) : Promise < boolean > {
6884 const stat = await this . stat ( ) ;
6985 return ! ! stat . canRead ;
7086 }
0 commit comments