Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to Delete Input File #381

Open
gclego opened this issue Apr 19, 2024 · 13 comments · May be fixed by #430
Open

Unable to Delete Input File #381

gclego opened this issue Apr 19, 2024 · 13 comments · May be fixed by #430

Comments

@gclego
Copy link

gclego commented Apr 19, 2024

Hi, first of all thank you for maintaining this project. Its awesome.

I just encountered an issue where I will merge two pdfs, then delete the files after wards. However I'm unable to delete the files and get an error EBUSY: resource busy or locked. Workaround is not to use Recipe, but would be great if this is fixed. Please see code below:

const Recipe = require('muhammara').Recipe;
const fs = require('fs');

const pdfDoc = new Recipe('test1.pdf', 'result.pdf');
const pdf2 = 'test2.pdf';

pdfDoc.appendPage(pdf2).endPDF();

// error here: Error: EBUSY: resource busy or locked, unlink 
fs.unlinkSync('test1.pdf');
fs.unlinkSync('test2.pdf');
@julianhille
Copy link
Owner

And the same node script can delete the files (without any user/owner / rights modification) if the node js process has been restarted?

@gclego
Copy link
Author

gclego commented Apr 22, 2024

yes. if I just delete the files, it works fine.

@julianhille
Copy link
Owner

you need to do that in the done callback:

const Recipe = require('muhammara').Recipe;
const fs = require('fs');

const pdfDoc = new Recipe('test1.pdf', 'result.pdf');
const pdf2 = 'test2.pdf';

pdfDoc.appendPage(pdf2).endPDF(() => {
  fs.unlinkSync('test1.pdf');
  fs.unlinkSync('test2.pdf');
});

// error here: Error: EBUSY: resource busy or locked, unlink 

@gclego
Copy link
Author

gclego commented Apr 23, 2024

still the same error :(

@julianhille
Copy link
Owner

I wrote a Test which does exactly this.
No issues there. Did you move the delete, for Testing purposes, to the first lines and return? So basically remove the recipe Code and then it works?

There is either some Race condition or you have that file Open somwewhere else.

Please also test if a setTimeout and unlink files later works. This might inidicate some Timing issues.

@gclego
Copy link
Author

gclego commented Apr 24, 2024

If I comment the Recipe code and just delete the files, it works. But when I put back the code, I'm getting the error. Also setTimeout does not work and the file is still locked. So I'm guessing something within the Recipe is not freeing up the files.

@julianhille
Copy link
Owner

please provide your os, arch and node version

@gclego
Copy link
Author

gclego commented May 5, 2024

windows x64 node 20.12.2

@mhamzabcs
Copy link

Does this ever got resolved? Same error same code on windows x64 node 20.12.2

@julianhille
Copy link
Owner

if i get the time for it of course. please test current dev by compiling your own version as there is a big pdf writer update which will be released shortly. that has a lot of internal changes and might fix this too.

julianhille added a commit that referenced this issue Oct 11, 2024
Relates to and shows that #381 is not an issue anymore.

Closes #381
@julianhille julianhille linked a pull request Oct 11, 2024 that will close this issue
@julianhille
Copy link
Owner

should be solved. see PR. can not reproduce it anymore. feel free to review the testcase i added

@julianhille
Copy link
Owner

it seems to be a windows issue. interesting

@julianhille
Copy link
Owner

Can you confirm you use muhammara in/with electron? Cause node only seems to run fine, even on windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants