From 7944cfe8d8193e0a7e6af9bb28460a5dceb1e428 Mon Sep 17 00:00:00 2001 From: "dr.dimitru" Date: Wed, 29 Jun 2022 23:13:24 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=91=A8=E2=80=8D=F0=9F=92=BB=20Fix:=20?= =?UTF-8?q?#842?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 👨‍💻 Fix #842, a newly detected bug by @chrschae; Fixing case when `namingFunction` returns new nested path cause exception in `.write()` and `.load()` methods --- server.js | 20 +++++++++++++------- write-stream.js | 1 + 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/server.js b/server.js index de59cf9..bf11de6 100644 --- a/server.js +++ b/server.js @@ -1254,9 +1254,12 @@ class FilesCollection extends FilesCollectionCore { result._id = fileId; - fs.stat(opts.path, (statErr, stats) => { + fs.stat(opts.path, (statError, stats) => { bound(() => { - if (statErr || !stats.isFile()) { + if (statError || !stats.isFile()) { + const paths = opts.path.split('/'); + paths.pop(); + fs.mkdirSync(paths.join('/'), { recursive: true }); fs.writeFileSync(opts.path, ''); } @@ -1364,9 +1367,12 @@ class FilesCollection extends FilesCollectionCore { }); }; - fs.stat(opts.path, (statErr, stats) => { + fs.stat(opts.path, (statError, stats) => { bound(() => { - if (statErr || !stats.isFile()) { + if (statError || !stats.isFile()) { + const paths = opts.path.split('/'); + paths.pop(); + fs.mkdirSync(paths.join('/'), { recursive: true }); fs.writeFileSync(opts.path, ''); } @@ -1394,10 +1400,10 @@ class FilesCollection extends FilesCollectionCore { }); if (!result.size) { - fs.stat(opts.path, (statError, newStats) => { + fs.stat(opts.path, (statErrorOnEnd, newStats) => { bound(() => { - if (statError) { - callback && callback(statError); + if (statErrorOnEnd) { + callback && callback(statErrorOnEnd); } else { result.versions.original.size = (result.size = newStats.size); storeResult(result, callback); diff --git a/write-stream.js b/write-stream.js index de05ec3..979b4ac 100644 --- a/write-stream.js +++ b/write-stream.js @@ -47,6 +47,7 @@ export default class WriteStream { fs.mkdirSync(paths.join('/'), { recursive: true }); fs.writeFileSync(this.path, ''); } + fs.open(this.path, 'r+', this.permissions, (oError, fd) => { bound(() => { if (oError) { From 96d969d31c2697c3b44282c7cfce176f829a7acb Mon Sep 17 00:00:00 2001 From: "dr.dimitru" Date: Wed, 29 Jun 2022 23:14:29 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=A6=20v2.2.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 👨‍💻 Fix #842, a newly detected bug by @chrschae; Fixing case when `namingFunction` returns new nested path cause exception in `.write()` and `.load()` methods --- .versions | 4 ++-- package.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.versions b/.versions index 950a78e..8a66b95 100644 --- a/.versions +++ b/.versions @@ -21,7 +21,7 @@ fetch@0.1.1 geojson-utils@1.0.10 id-map@1.1.1 inter-process-messaging@0.1.1 -local-test:ostrio:files@2.2.0 +local-test:ostrio:files@2.2.1 logging@1.3.1 meteor@1.10.0 minimongo@1.8.0 @@ -35,7 +35,7 @@ mongo-id@1.0.8 npm-mongo@4.3.1 ordered-dict@1.1.0 ostrio:cookies@2.7.2 -ostrio:files@2.2.0 +ostrio:files@2.2.1 promise@0.12.0 random@1.2.0 react-fast-refresh@0.2.3 diff --git a/package.js b/package.js index 3d59f2b..a32abfe 100755 --- a/package.js +++ b/package.js @@ -1,6 +1,6 @@ Package.describe({ name: 'ostrio:files', - version: '2.2.0', + version: '2.2.1', summary: 'Upload files to a server or 3rd party storage: AWS:S3, GridFS, DropBox, and other', git: 'https://github.com/veliovgroup/Meteor-Files', documentation: 'README.md'