Skip to content

Commit

Permalink
Merge pull request #49 from seald/48-eperm-root-directory-win32
Browse files Browse the repository at this point in the history
Fix EPERM error when instantiating database in root directory on win32
  • Loading branch information
tex0l authored Dec 13, 2023
2 parents a0fa8da + 6903ffa commit 2229821
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Fixed EPERM Exception when datastore is at the root of a disk on Windows [#48](https://github.com/seald/nedb/issues/48)

## [4.0.2] - 2023-05-05
### Fixed
- Fixed typo in documentation [#36](https://github.com/seald/nedb/pull/36)
Expand Down
6 changes: 5 additions & 1 deletion lib/persistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,11 @@ class Persistence {
* @private
*/
static async ensureDirectoryExistsAsync (dir, mode = DEFAULT_DIR_MODE) {
await storage.mkdirAsync(dir, { recursive: true, mode })
const parsedDir = path.parse(path.resolve(dir))
// this is because on Windows mkdir throws a permission error when called on the root directory of a volume
if (process.platform !== 'win32' || parsedDir.dir !== parsedDir.root || parsedDir.base !== '') {
await storage.mkdirAsync(dir, { recursive: true, mode })
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@seald-io/nedb",
"version": "4.0.2",
"version": "4.0.3-1",
"files": [
"lib/**/*.js",
"browser-version/**/*.js",
Expand Down

0 comments on commit 2229821

Please sign in to comment.