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

Issue with store creating multiple .temp files and having issues writing to it #7

Closed
ratanservegar opened this issue Jul 20, 2023 · 5 comments

Comments

@ratanservegar
Copy link

Hi,

I was asked to open a issue here by sindresorhus as he mentioned that you could help here (original request - sindresorhus/electron-store#261)

Issue:

I have a stored named MasterStore and it creates a MasterStore.json files and everything works prefect. However, after sometime for some reason the .setCache function errors out because it is trying to access some MasterStore.json.temp file. below is the error log

Error: EPERM: operation not permitted, rename 'C:\Users\AppData\Roaming\neclient\MasterStore.json.tmp-900921090850e765' -> 'C:\Users\AppData\Roaming\neclient\MasterStore.json' at renameSync (node:fs:993:3) at attempt (C:\Users\AppData\Local\Programs\neclient\resources\app\node_modules\atomically\dist\utils\retryify.js:33:27) at attempt (C:\Users\AppData\Local\Programs\neclient\resources\app\node_modules\atomically\dist\utils\retryify.js:39:36) at attempt (C:\Users\AppData\Local\Programs\neclient\resources\app\node_modules\atomically\dist\utils\retryify.js:39:36) at Object.writeFileSync (C:\Users\AppData\Local\Programs\neclient\resources\app\node_modules\atomically\dist\index.js:160:50) at ElectronStore._write (C:\Users\AppData\Local\Programs\neclient\resources\app\node_modules\conf\dist\source\index.js:375:28) at set store [as store] (C:\Users\AppData\Local\Programs\neclient\resources\app\node_modules\conf\dist\source\index.js:296:14) at ElectronStore.set (C:\Users\AppData\Local\Programs\neclient\resources\app\node_modules\conf\dist\source\index.js:189:20) at Object.setCacheValue (C:\Users\AppData\Local\Programs\neclient\resources\app\system_services\cache-service.js:59:21) at BeforeAppShutDown (C:\Users\AppData\Local\Programs\neclient\resources\app\main.js:352:23)

i crate the store using
const masterStore = new Store({ name: 'MasterStore' });
and set contents by masterStore.set(key, value);

can someone tell me what's the reason its doing this? and how i can fix it?

@ratanservegar
Copy link
Author

no one?

@fabiospampinato
Copy link
Owner

Do you have a repro I can try?

conf is updating its stores synchronously (sindresorhus/electron-store#106), which doesn't give this library a lot of time to write the file to disk, as it can't just block the main thread for a long time, it should be writing asynchronously instead if possible, that would give it more time to retry operations.

Other than that Windows is a dumpster fire, if for whatever reason it just doesn't allow you to rename a file there's nothing the library can do to force it.

I guess this library could try to write non-atomically in those situations, but that's nonsense for a library that explicitly provides atomic writes.

@ratanservegar
Copy link
Author

Hi @fabiospampinato,
thanks for the explanation, no I do not have a public repo of my app that you can use. My application is in electron-js and I use a cache package called electron-store which uses your lib.

@fabiospampinato
Copy link
Owner

It's something for electron-store to do

@ratanservegar
Copy link
Author

Thanks, I will see if the author of electron-store does something.

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

No branches or pull requests

2 participants