From d470cfeeed1dc78e576bf4b55cf3bd5c2be25a85 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sun, 24 Feb 2019 10:11:56 +0100 Subject: [PATCH] fix: overrides existing package to zero bytes file #1191 Publishing existing package overrides existing package to 0 bytes file --- package.json | 2 +- src/lib/local-storage.js | 4 +++- test/unit/api/local-storage.spec.js | 6 ------ yarn.lock | Bin 394083 -> 394083 bytes 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index b9ea13dc6..08556f289 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ }, "dependencies": { "@verdaccio/file-locking": "0.0.8", - "@verdaccio/local-storage": "1.1.6", + "@verdaccio/local-storage": "1.1.7", "@verdaccio/streams": "1.0.0", "JSONStream": "1.3.5", "async": "3.0.1-0", diff --git a/src/lib/local-storage.js b/src/lib/local-storage.js index 2bd3ac9a3..f854bd5fd 100644 --- a/src/lib/local-storage.js +++ b/src/lib/local-storage.js @@ -222,7 +222,9 @@ class LocalStorage implements IStorage { metadata = cleanUpReadme(metadata); metadata.contributors = normalizeContributors(metadata.contributors); - if (data.versions[version] != null) { + + const hasVersion = data.versions[version] != null; + if (hasVersion) { return cb( ErrorCode.getConflict() ); } diff --git a/test/unit/api/local-storage.spec.js b/test/unit/api/local-storage.spec.js index 8d398c767..2e4f93234 100644 --- a/test/unit/api/local-storage.spec.js +++ b/test/unit/api/local-storage.spec.js @@ -364,16 +364,10 @@ describe('LocalStorage', () => { test('should fails on add a duplicated new tarball ', (done) => { const tarballData = JSON.parse(readMetadata('addTarball')); const stream = storage.addTarball(pkgName, tarballName); - let spy; - // $FlowFixMe - spy = jest.spyOn(stream && stream._readableState && stream._readableState.pipes, 'abort'); stream.on('error', (err) => { expect(err).not.toBeNull(); expect(err.statusCode).toEqual(HTTP_STATUS.CONFLICT); expect(err.message).toMatch(/this package is already present/); - }); - stream.on('success', function(){ - expect(spy).toHaveBeenCalled(); done(); }); stream.end(new Buffer(tarballData.data, 'base64')); diff --git a/yarn.lock b/yarn.lock index 4b2ad276587e01b2c63e2ae60d7740426ba78a52..542ea5d7cff7185310de816dbd1751e03d835d8b 100644 GIT binary patch delta 199 zcmaFdCh@pUVgsWxleyCLf3q2_C)+9O>YD47q*p1M87C)O7#gLe86=q|8mFX~rJ7nA zTBH~mTN)afT3A?^nwc9L8>CJTJjf~*mXn$3WLOazZmjJV6`bmxndf2QmK~_=?qyPJ z85kN??xpXOm6aaqn^hTHm}C)=SsCnDoD^0S77`Vh91-jonV#xnnV;(%>5*1mT;^uLE#d8R)&$ST$BsM7AJ!U)7nK+FupEZZGbSe5Pr0OG?yl>h($ delta 200 zcmaFdCh@pUVgsWxlbO#a1-b;5ny0vB<&-BoyG43MS(c^ymj{O$MR?^^xOr$NW@zW7yLkq>Iq8>& wxK~wq8>Kr=Z=B93KK<_@R-Wk(4zfx$JF2uhsxSgE6A&{4G0S#G6;`GD06)(`8vp