Skip to content

Commit a055199

Browse files
add moe logging
1 parent 3222b77 commit a055199

2 files changed

Lines changed: 41 additions & 23 deletions

File tree

src/fileSystem/SAFDocumentFile.ts

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/lib/run.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ async function run(
4949
let root = documentFile;
5050
if (await projectFolder.isMyChild(documentFile)) {
5151
root = projectFolder;
52+
log.d("Not a child of project folder");
5253
} else {
5354
root = await documentFile.getParentFile();
54-
if (root == null || (await root.exists())) {
55+
if (root == null || (!await root.exists())) {
5556
root = documentFile;
57+
log.d("llll")
5658
}
5759
}
5860

0 commit comments

Comments
 (0)