electron-userland / electron-json-storage

:package: Easily write and read user settings in Electron apps
1.44k stars 80 forks source link

Space and brackets in userData cause ENOENT #41

Closed janekolszak closed 7 years ago

janekolszak commented 7 years ago

Hi, great library!

Having app.getPath('userData') like this: .config/Electron Boilerplate (development) results in ENOENT:

{ Error: ENOENT: no such file or directory, open '.config/Electron Boilerplate/data.json'
    at Error (native)
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '.config/Electron Boilerplate/data.json' }
jviotti commented 7 years ago

Hi @janekolszak ,

Thanks for reaching out! Is this something you've manually set using app.setPath? Is the intention here to have the user data directory relative to the application directory?

If so, we could detect if the user data directory is absolute, and if not, use path.join with the current working directory.

Let me know if that is the case!

P.S: I believe doing something like ./.config instead of .config could be a quick way to get unblocked until we resolve the issue.

janekolszak commented 7 years ago

No, I just removed my home directory from the logs :)

If app.getPath('userData') is like this: /home/me/.config/Electron Boilerplate (development) then electron-storage-jsan will look for data in /home/me/.config/Electron Boilerplate/data.json

jviotti commented 7 years ago

I gave this a go and couldn't reproduce any error when setting a userPath containing spaces and/or parenthesis, however I did get ENOENT if the userData path I specified didn't exist, so I'm assuming that is the root cause here.

I just sent a PR fixing that issue.

jviotti commented 7 years ago

Check v2.1.1. Let me know if you still have any other issues with it!