Error when creating index: illegal operation on a directory #197
Replies: 27 comments
-
@chinonso098 I've included the output of
|
Beta Was this translation helpful? Give feedback.
-
Thanks |
Beta Was this translation helpful? Give feedback.
-
This is the index.json file created in ZenFS This is the osdrive.json file created in BrowserFS in BrowserFS, for me to access the contents of the filesystem, I did fs.readdir('/osdrive/Desktop' ......), and it would pull the contents in the Desktop folder. In ZenFS, I tried fs.readdir('/Desktop' ......) and I get Error: No such file or directory. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Here is what my code looks like import osDriveFileSystemIndex1 from '../../../index.json';
import ini from 'ini';
import { configure, fs, Overlay, Fetch } from '@zenfs/core';
import { IndexedDB } from '@zenfs/dom';
@Injectable({
providedIn: 'root',
})
export class FileService {
private async initZenFSAsync(): Promise<void> {
return new Promise<void>((resolve, reject) => {
configure<typeof Overlay>({
mounts: {
'/': {
backend: Overlay,
readable: { backend: Fetch, index: osDriveFileSystemIndex1 },
writable: { backend: IndexedDB, storeName: 'fs-cache' },
},
},
});
resolve(console.log('ZenFS is Ready!!!'));
});
}
public async getFilesFromDirectoryAsync1(): Promise<void> {
// await this.initBrowserFsAsync();
await this.initZenFSAsync().then(() => {
fs.readdir('/', (err, files) => {
if (err) {
console.log("Oops! a boo boo happened, filesystem wasn't ready:", err);
} else {
console.log('Here are the files:', files);
}
});
});
}
public getFilesFromDirectorySync(): void {
const result = fs.readdirSync('/');
console.log(`Here are the files: ${result}`);
}
public async getFilesFromDirectoryAsync(dirPath: string): Promise<unknown> {
await this.initBrowserFsAsync();
// ...
}
// ...
} For the
For the
|
Beta Was this translation helpful? Give feedback.
-
I attempted to reproduce the error: import { configure, fs, Overlay, Fetch } from '@zenfs/core';
import { IndexedDB } from '@zenfs/dom';
await configure({
mounts: {
'/': {
backend: Overlay,
readable: {
backend: Fetch,
index: './index.json',
baseUrl: 'data',
},
writable: { backend: IndexedDB, storeName: 'fs-cache' },
},
},
});
console.log('FS configured');
console.log('readdir / (async):', await fs.promises.readdir('/'));
console.log('readdir / (sync):', fs.readdirSync('/'));
console.log('readdir /nested:', await fs.promises.readdir('/nested'));
console.log('readFile /one.txt:', await fs.promises.readFile('/one.txt', 'utf8')); Directory structure:
But it gave me the correct and expected output:
|
Beta Was this translation helpful? Give feedback.
-
Hmmmm....... i guess it's something on my end. Let me keep digging |
Beta Was this translation helpful? Give feedback.
-
I recommend you rewrite 2 of the class methods, since they are somewhat difficult to read, and use export class FileService {
private async initZenFSAsync(): Promise<void> {
await configure<typeof Overlay>({
mounts: {
'/': {
backend: Overlay,
readable: { backend: Fetch, index: osDriveFileSystemIndex1 },
writable: { backend: IndexedDB, storeName: 'fs-cache' },
},
},
});
console.log('ZenFS is Ready!!!'));
}
public async getFilesFromDirectoryAsync1(): Promise<void> {
// await this.initBrowserFsAsync();
await this.initZenFSAsync();
try {
console.log('Here are the files:', await fs.promises.readdir('/'));
} catch (err) {
console.log("Ooops! a boo boo happened, filesystem wasn't ready:", err);
}
}
// ...
} |
Beta Was this translation helpful? Give feedback.
-
Again, thanks a lot for the assist. I will implement the changes and get back to you. |
Beta Was this translation helpful? Give feedback.
-
@chinonso098 What are the entries in the You can log either const readable = await resolveMountConfig({ backend: Fetch, index: osDriveFileSystemIndex1 });
console.log(readable.index);
await configure<typeof Overlay>({
mounts: {
'/': {
backend: Overlay,
readable,
writable: { backend: IndexedDB, storeName: 'fs-cache' },
},
},
}); Note you may have to ignore a Typescript error about protected/private members. |
Beta Was this translation helpful? Give feedback.
-
here are some of the entries (Document, Games, Pictures, Music, icons ...) Here is the Index file. |
Beta Was this translation helpful? Give feedback.
-
I know the index.json has the files you mentioned... I'm refering to the runtime |
Beta Was this translation helpful? Give feedback.
-
I tried to do what you asked, but i get a 'Type number is not assignable to 1' error |
Beta Was this translation helpful? Give feedback.
-
Also, for some strange reason, i missed informing you about this error the error points to line 92 of the file.services.ts file. It seems like it is accessing the index file, but it fails to find the data on the server |
Beta Was this translation helpful? Give feedback.
-
I get the error : 'Property 'fs' does not exist on type FileSystem' when I try this code |
Beta Was this translation helpful? Give feedback.
-
This is because the imported index's type is not strict enough. You can cast the index object (
You probably need to set the
You should have an Basically: |
Beta Was this translation helpful? Give feedback.
-
what do I set the baseUrl to? Ok, minor progress. I set baseUrl to baseUrl:'osdrive' osdrive is the actual folder containing the contents from which the index.json file was created. The 404 error message is gone, but I still get an empty array for fs.promise.readdir('/') And attempting to the cast the index object to IndexJSON fails Basically: Ummm.............um....ok |
Beta Was this translation helpful? Give feedback.
-
You need to import As for the value of |
Beta Was this translation helpful? Give feedback.
-
I tried to import |
Beta Was this translation helpful? Give feedback.
-
No, It is defined in src/backends/index/index.ts:12 as |
Beta Was this translation helpful? Give feedback.
-
Thank you, thank you, thank you We have data 🙂🙂🙂 |
Beta Was this translation helpful? Give feedback.
-
So was it because of |
Beta Was this translation helpful? Give feedback.
-
Correct, it was the baseUrl |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
No. If you would like to continue using a flag, A guard clause would be more readable (and decrease indentation): private async initZenFSAsync(): Promise<void> {
if(this._isFileSystemInit) {
return;
}
await configure({
// ...
});
this._isFileSystemInit = true;
} Also @chinonso098 Please stop posting screenshots of your code. It is next to impossible to copy the code, which is making helping you very difficult. As stated in the contributing.md, "Please copy logs, terminal output, and code into a code block in the issue or PR. Do not include screenshots since those are very difficult to debug." So far I've manually been rewriting your screenshots into code blocks but it is making me a little frustrated. Sorry to give you all this, but its important to follow the guidelines on issues. |
Beta Was this translation helpful? Give feedback.
-
Will do next time. Again Thanks a lot for the assist. 🙂 |
Beta Was this translation helpful? Give feedback.
-
@chinonso098 No problem please let me know if you have more issues. I also encourage you to look at the documentation before opening an issue since many times the problem can be solved without opening an issue (like with |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When I run the command
npx make-index --output src\osdrive
ornpx make-index -o src\osdrive
, i get the same illegal operation on a directory error.What could be the cause? And again, thanks for the assist
Beta Was this translation helpful? Give feedback.
All reactions