+7
-0
@@ -5,2 +5,9 @@ # Changelog | ||
| ### [0.1.5](https://github.com/unjsio/unstorage/compare/v0.1.4...v0.1.5) (2021-04-16) | ||
| ### Bug Fixes | ||
| * **fs:** race condition for ensuredir ([437cc76](https://github.com/unjsio/unstorage/commit/437cc76824fea7121107aaa45a17bd47155a6201)) | ||
| ### [0.1.4](https://github.com/unjsio/unstorage/compare/v0.1.3...v0.1.4) (2021-04-14) | ||
@@ -7,0 +14,0 @@ |
+11
-12
@@ -295,5 +295,8 @@ #!/usr/bin/env node | ||
| function isNotFound(err) { | ||
| return err.code === "ENOENT" || err.code === "EISDIR"; | ||
| function ignoreNotfound(err) { | ||
| return err.code === "ENOENT" || err.code === "EISDIR" ? null : err; | ||
| } | ||
| function ignoreExists(err) { | ||
| return err.code === "EEXIST" ? null : err; | ||
| } | ||
| async function writeFile(path$1, data) { | ||
@@ -304,20 +307,16 @@ await ensuredir(path.dirname(path$1)); | ||
| function readFile(path) { | ||
| return fs.promises.readFile(path, "utf8").catch((err) => isNotFound(err) ? null : Promise.reject(err)); | ||
| return fs.promises.readFile(path, "utf8").catch(ignoreNotfound); | ||
| } | ||
| function stat(path) { | ||
| return fs.promises.stat(path).catch((err) => isNotFound(err) ? null : Promise.reject(err)); | ||
| } | ||
| function unlink(path) { | ||
| return fs.promises.unlink(path).catch((err) => isNotFound(err) ? void 0 : Promise.reject(err)); | ||
| return fs.promises.unlink(path).catch(ignoreNotfound); | ||
| } | ||
| function readdir(dir) { | ||
| return fs.promises.readdir(dir, {withFileTypes: true}).catch((err) => isNotFound(err) ? [] : Promise.reject(err)); | ||
| return fs.promises.readdir(dir, {withFileTypes: true}).catch(ignoreNotfound); | ||
| } | ||
| async function ensuredir(dir) { | ||
| const _stat = await stat(dir); | ||
| if (_stat && _stat.isDirectory()) { | ||
| if (fs.existsSync(dir)) { | ||
| return; | ||
| } | ||
| await ensuredir(path.dirname(dir)); | ||
| await fs.promises.mkdir(dir); | ||
| await ensuredir(path.dirname(dir)).catch(ignoreExists); | ||
| await fs.promises.mkdir(dir).catch(ignoreExists); | ||
| } | ||
@@ -324,0 +323,0 @@ async function readdirRecursive(dir, ignore) { |
| /// <reference types="node" /> | ||
| import { Dirent } from 'fs'; | ||
| export declare function writeFile(path: string, data: string): Promise<void>; | ||
| export declare function readFile(path: string): Promise<string>; | ||
| export declare function stat(path: string): Promise<import("fs").Stats>; | ||
| export declare function unlink(path: string): Promise<void>; | ||
| export declare function readFile(path: string): Promise<any>; | ||
| export declare function stat(path: string): Promise<any>; | ||
| export declare function unlink(path: string): Promise<any>; | ||
| export declare function readdir(dir: string): Promise<Dirent[]>; | ||
@@ -8,0 +8,0 @@ export declare function ensuredir(dir: string): Promise<void>; |
+13
-11
@@ -19,6 +19,10 @@ "use strict"; | ||
| function isNotFound(err) { | ||
| return err.code === "ENOENT" || err.code === "EISDIR"; | ||
| function ignoreNotfound(err) { | ||
| return err.code === "ENOENT" || err.code === "EISDIR" ? null : err; | ||
| } | ||
| function ignoreExists(err) { | ||
| return err.code === "EEXIST" ? null : err; | ||
| } | ||
| async function writeFile(path, data) { | ||
@@ -30,11 +34,11 @@ await ensuredir((0, _path.dirname)(path)); | ||
| function readFile(path) { | ||
| return _fs.promises.readFile(path, "utf8").catch(err => isNotFound(err) ? null : Promise.reject(err)); | ||
| return _fs.promises.readFile(path, "utf8").catch(ignoreNotfound); | ||
| } | ||
| function stat(path) { | ||
| return _fs.promises.stat(path).catch(err => isNotFound(err) ? null : Promise.reject(err)); | ||
| return _fs.promises.stat(path).catch(ignoreNotfound); | ||
| } | ||
| function unlink(path) { | ||
| return _fs.promises.unlink(path).catch(err => isNotFound(err) ? void 0 : Promise.reject(err)); | ||
| return _fs.promises.unlink(path).catch(ignoreNotfound); | ||
| } | ||
@@ -45,14 +49,12 @@ | ||
| withFileTypes: true | ||
| }).catch(err => isNotFound(err) ? [] : Promise.reject(err)); | ||
| }).catch(ignoreNotfound); | ||
| } | ||
| async function ensuredir(dir) { | ||
| const _stat = await stat(dir); | ||
| if (_stat && _stat.isDirectory()) { | ||
| if ((0, _fs.existsSync)(dir)) { | ||
| return; | ||
| } | ||
| await ensuredir((0, _path.dirname)(dir)); | ||
| await _fs.promises.mkdir(dir); | ||
| await ensuredir((0, _path.dirname)(dir)).catch(ignoreExists); | ||
| await _fs.promises.mkdir(dir).catch(ignoreExists); | ||
| } | ||
@@ -59,0 +61,0 @@ |
+1
-1
| { | ||
| "name": "unstorage", | ||
| "version": "0.1.4", | ||
| "version": "0.1.5", | ||
| "description": "", | ||
@@ -5,0 +5,0 @@ "repository": "unjsio/unstorage", |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
60669
0.04%1445
0.07%11
-8.33%