fix: create missing directories with app.setPath (#18244)

This commit is contained in:
Shelley Vohr 2019-05-28 10:37:54 -07:00 committed by GitHub
parent 1688ebdd40
commit c621615112
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View file

@ -580,7 +580,7 @@ them.
* `path` String (optional) - A custom path for your logs. Must be absolute.
Sets or creates a directory your app's logs which can then be manipulated with `app.getPath()` or `app.setPath(newPath)`.
Sets or creates a directory your app's logs which can then be manipulated with `app.getPath()` or `app.setPath(pathName, newPath)`.
On _macOS_, this directory will be set by deafault to `/Library/Logs/YourAppName`, and on _Linux_ and _Windows_ it will be placed inside your `userData` directory.
@ -641,9 +641,9 @@ On _Linux_ and _macOS_, icons depend on the application associated with file mim
* `name` String
* `path` String
Overrides the `path` to a special directory or file associated with `name`. If
the path specifies a directory that does not exist, the directory will be
created by this method. On failure an `Error` is thrown.
Overrides the `path` to a special directory or file associated with `name`.
If the path specifies a directory that does not exist, an `Error` is thrown.
In that case, the directory should be created with `fs.mkdirSync` or similar.
You can only override paths of a `name` defined in `app.getPath`.

View file

@ -667,6 +667,18 @@ describe('app module', () => {
})
})
describe('setPath(name, path)', () => {
it('does not create a new directory by default', () => {
const badPath = path.join(__dirname, 'music')
expect(fs.existsSync(badPath)).to.be.false
app.setPath('music', badPath)
expect(fs.existsSync(badPath)).to.be.false
expect(() => { app.getPath(badPath) }).to.throw()
})
})
describe('select-client-certificate event', () => {
let w: BrowserWindow