From a83e80759dfb497364b59c857d15e3fae38e3c23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Rebours?= Date: Tue, 12 Dec 2023 17:51:45 +0100 Subject: [PATCH 1/4] Fix #48 --- CHANGELOG.md | 4 ++++ lib/persistence.js | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) 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 }) + } } } From 03217cead9a93616a14b58bccb4a4bc7bd2e459f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Rebours?= Date: Tue, 12 Dec 2023 18:06:17 +0100 Subject: [PATCH 2/4] 4.0.3-0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index e225b5e..181a905 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@seald-io/nedb", - "version": "4.0.2", + "version": "4.0.3-0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@seald-io/nedb", - "version": "4.0.2", + "version": "4.0.3-0", "license": "MIT", "dependencies": { "@seald-io/binary-search-tree": "^1.0.3", diff --git a/package.json b/package.json index de5c60f..1ef4ced 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@seald-io/nedb", - "version": "4.0.2", + "version": "4.0.3-0", "files": [ "lib/**/*.js", "browser-version/**/*.js", From afe183148516f7c72e0dd6611503852b879dc9c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Rebours?= Date: Wed, 13 Dec 2023 15:42:23 +0100 Subject: [PATCH 3/4] fix more properly #48 after reading path.parse documentation more thoroughly --- lib/persistence.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/persistence.js b/lib/persistence.js index f10ec57..ba359a5 100755 --- a/lib/persistence.js +++ b/lib/persistence.js @@ -375,7 +375,7 @@ class Persistence { static async ensureDirectoryExistsAsync (dir, mode = DEFAULT_DIR_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) { + if (process.platform !== 'win32' || parsedDir.dir !== parsedDir.root || parsedDir.base !== '') { await storage.mkdirAsync(dir, { recursive: true, mode }) } } From 6903ffa42bccddda939ed75798da227d168c723f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Rebours?= Date: Wed, 13 Dec 2023 15:42:27 +0100 Subject: [PATCH 4/4] 4.0.3-1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 181a905..8d034ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@seald-io/nedb", - "version": "4.0.3-0", + "version": "4.0.3-1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@seald-io/nedb", - "version": "4.0.3-0", + "version": "4.0.3-1", "license": "MIT", "dependencies": { "@seald-io/binary-search-tree": "^1.0.3", diff --git a/package.json b/package.json index 1ef4ced..db0c660 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@seald-io/nedb", - "version": "4.0.3-0", + "version": "4.0.3-1", "files": [ "lib/**/*.js", "browser-version/**/*.js",