diff --git a/CHANGELOG.md b/CHANGELOG.md index c77fc4f..52ca22c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/persistence.js b/lib/persistence.js index 28e0e21..f10ec57 100755 --- a/lib/persistence.js +++ b/lib/persistence.js @@ -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) { + await storage.mkdirAsync(dir, { recursive: true, mode }) + } } }