In all my search attempts, I could only find people trying to fix an "EBUSY: resource busy or locked" error.
What I want is to intentionally put a file in this state (temporarily). How can this be done?
I tried using fs.open, fs.createReadStream and fs.createWriteStream from NodeJS, but for my surprise this doesn't make the file busy.
How can I do this? Preferably in NodeJS, but it can be in any language.
On .NET Core, you can use FileStream.Lock().
Here's the API documentation from .NET Core 3.1 which includes a sample .NET program also that does locking a file exclusively, which should trigger the 'EBUSY: resource busy or locked' error in node JS programs trying to access the same file.
The FileStream.Lock() API call signature is:
public virtual void Lock (long position, long length);
You can call it with position set to 0 and length set to the length of the file. FileStream.Lock() on Windows allows locking file ranges.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With