mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-13 22:48:31 -05:00
fix: Fix storing same named files from different pkgs in memory plugin (#3200)
The memory plugin was not correctly writing tarballs that have the same name but are from different packages and have different content.
This commit is contained in:
parent
ef793182d5
commit
b8981136b0
3 changed files with 78 additions and 27 deletions
5
.changeset/chilled-ways-fetch.md
Normal file
5
.changeset/chilled-ways-fetch.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'verdaccio-memory': patch
|
||||
---
|
||||
|
||||
Fix storing tarballs with identical names from different packages in memory plugin
|
|
@ -1,5 +1,6 @@
|
|||
import buildDebug from 'debug';
|
||||
import { fs } from 'memfs';
|
||||
import path from 'path';
|
||||
|
||||
import { VerdaccioError, errorUtils } from '@verdaccio/core';
|
||||
import { ReadTarball, UploadTarball } from '@verdaccio/streams';
|
||||
|
@ -35,7 +36,7 @@ class MemoryHandler implements IPackageStorageManager {
|
|||
this.data = data;
|
||||
this.name = packageName;
|
||||
this.logger = logger;
|
||||
this.path = '/';
|
||||
this.path = `/${packageName}`;
|
||||
debug('initialized');
|
||||
}
|
||||
|
||||
|
@ -113,11 +114,15 @@ class MemoryHandler implements IPackageStorageManager {
|
|||
}
|
||||
|
||||
public writeTarball(name: string): IUploadTarball {
|
||||
debug('write tarball %o', name);
|
||||
const uploadStream: IUploadTarball = new UploadTarball({});
|
||||
const temporalName = `/${name}`;
|
||||
const temporalName = `${this.path}/${name}`;
|
||||
debug('write tarball %o', temporalName);
|
||||
|
||||
process.nextTick(function () {
|
||||
fs.mkdirp(path.dirname(temporalName), (mkdirpError) => {
|
||||
if (mkdirpError) {
|
||||
return uploadStream.emit('error', mkdirpError);
|
||||
}
|
||||
fs.stat(temporalName, function (fileError, stats) {
|
||||
if (!fileError && stats) {
|
||||
return uploadStream.emit('error', errorUtils.getConflict());
|
||||
|
@ -149,13 +154,14 @@ class MemoryHandler implements IPackageStorageManager {
|
|||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return uploadStream;
|
||||
}
|
||||
|
||||
public readTarball(name: string): IReadTarball {
|
||||
const pathName = `/${name}`;
|
||||
debug('read tarball %o', name);
|
||||
const pathName = `${this.path}/${name}`;
|
||||
debug('read tarball %o', pathName);
|
||||
|
||||
const readTarballStream: IReadTarball = new ReadTarball({});
|
||||
|
||||
|
|
|
@ -299,6 +299,46 @@ describe('writing files', () => {
|
|||
});
|
||||
}
|
||||
});
|
||||
|
||||
test('should support writting identical tarball filenames from different packages', (done) => {
|
||||
const localMemory: IPluginStorage<ConfigMemory> = new LocalMemory(config, defaultConfig);
|
||||
const pkgName1 = 'package1';
|
||||
const pkgName2 = 'package2';
|
||||
const filename = 'tarball-3.0.0.tgz';
|
||||
const dataTarball1 = '12345';
|
||||
const dataTarball2 = '12345678';
|
||||
const handler = localMemory.getPackageStorage(pkgName1);
|
||||
if (handler) {
|
||||
const stream = handler.writeTarball(filename);
|
||||
stream.on('data', (data) => {
|
||||
expect(data.toString()).toBe(dataTarball1);
|
||||
});
|
||||
stream.on('open', () => {
|
||||
stream.done();
|
||||
stream.end();
|
||||
});
|
||||
stream.on('success', () => {
|
||||
const handler = localMemory.getPackageStorage(pkgName2);
|
||||
if (handler) {
|
||||
const stream = handler.writeTarball(filename);
|
||||
stream.on('data', (data) => {
|
||||
expect(data.toString()).toBe(dataTarball2);
|
||||
});
|
||||
stream.on('open', () => {
|
||||
stream.done();
|
||||
stream.end();
|
||||
});
|
||||
stream.on('success', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
stream.write(dataTarball2);
|
||||
}
|
||||
});
|
||||
|
||||
stream.write(dataTarball1);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('reading files', () => {
|
||||
|
|
Loading…
Add table
Reference in a new issue