isomorphic-git / lightning-fs

A lean and fast 'fs' for the browser
MIT License
476 stars 47 forks source link

Allow a recursive option on rmdir #71

Open amxmln opened 3 years ago

amxmln commented 3 years ago

The rmdir function in newer versions of Node allows for a recursive option that when set to true makes the command behave more like a rm -rf, which I think can be very useful in many situations (such as deleting a cloned but no longer needed git repo for example).

The documentation of lightning-fs suggests that its rmdir also takes an options object, but I browsing through the source I couldn’t find anything that seemed to be using that object (I might have missed something though :sweat_smile:). I feel like adding a native recursive option could really benefit the library and perhaps would even allow for a more efficient way than a recursive "rimraf" implemented on top of the library, since if I understood the structure of lightning-fs correctly it should be possible to just gather a list of all inodes contained in the directory, delete them and then delete the directory itself in a single transaction, right?

Sorry if that suggested solution is useless, but I hope the rest of my point still stands.

Keep up the great work! :tada:

SaadBazaz commented 1 year ago

Needed!

jcubic commented 1 year ago

@SaadBazaz do you want to contribute?

SaadBazaz commented 1 year ago

@jcubic I can try giving it a go. Any pointers to where I can start?

jcubic commented 1 year ago

You should just get familiar with the code, it was a while when I read the code I don't remember where you should start. But there are not much code in this project.

kaytwo commented 1 year ago

FWIW I ran into this issue and just used unlink on a directory and it worked as I expected it to (equivalent to rm -rf). Looking at the implementation, this will probably leave "garbage" in the virtual filesystem, but if you're doing something in an ephemeral filesystem it should probably meet your needs.

amxmln commented 1 year ago

Yes, it will not actually delete the files, they will just become inaccessible, because their parent is removed. They will still take up disk space, however, like you said.

7flash commented 21 minutes ago

mkdir also missing recursive option