isomorphic-git / lightning-fs

A lean and fast 'fs' for the browser
MIT License
487 stars 48 forks source link

Problem with backend option #124

Closed bajrangCoder closed 11 months ago

bajrangCoder commented 11 months ago

I am creating a wrapper of my fs using lighting fs backend option but I am not able to perform these stuff:

And all other operation work well like read, stat, etc...

What should I do to perform these create, write, etc stuff?

jcubic commented 11 months ago

Did you implement the required interface for the backend object? Also, what do you mean by not working? Do you have some errors?

bajrangCoder commented 11 months ago

Yes , I have implemented the required things. And error is related to permission and contains that one IDB superBlock method isn't defined

jcubic commented 11 months ago

Do you have the code somewhere online where I can test it? IDB should not be used when using the custom backend. Maybe I made a mistake when added the db option (it has the superBlock methods), this is the option to change the internal database for defaultBackend that use IndexedDB.

bajrangCoder commented 11 months ago

Here is my backend fs code: https://dpaste.org/CZuO1 And here is how I am using it in my case: https://dpaste.org/SX3oM

And here is screenshot of error: Screenshot_20231030-081733

jcubic commented 11 months ago

I was looking at the source code and it seems that saveSuperblock function is needed. The default implementation is just calling flush so send the data to indexedDB if they are buffered.

I don't think it will be a good idea to remove this dependency, I'll update the documentation to include save and load superBlock or maybe change them to init() and flush() since this is what the implementation is actually doing and superBlock is just implementation details of idexedDB based code.

So for now if you save directly to filesystem you can implementation this method and leave it blank.

bajrangCoder commented 11 months ago

thanks it worked! I have just passed empty : saveSuperblock and loadSuperblock in custom backend class.

and i have a question: is readlink, symlink , lstat is required in isomorphic-git ? My fs don't have this !

jcubic commented 11 months ago

I'm not sure about link but lstat is probbably require for git.status() or statusMatrix. You can check this function and see if you will get the error. You can also search the code and see if link functions are used. You can search directly on GitHub.

bajrangCoder commented 11 months ago

Yeah , I have checked isomorphic-git src and these are needed and also lstat is needed in clonning repo but Unfortunately I don't have lstat , symlink etc on Android internal storage (my fs)

jcubic commented 11 months ago

You need to simulate the lstat using some different API like checking if path is file or directory and if it exists. You need to implement same API as in NodeJS.

Check nodejs documentation, you need to return this object https://nodejs.org/api/fs.html#class-fsstats most of the stuff is probably not needed. Check the source code on what values are used and implement those. You can also check what are implemented in indexedDB-based defaultBackend.

jcubic commented 11 months ago

I will just check if the library work without lstat (add function that returns empty object), I was checking the code, I'm not sure if GitHub showed everything, but fs.stat is used only in unit tests. So if you use isomorphic-git it should work without fs.stat(). But I'm not 100% sure.