Skip to content

Commit

Permalink
Use pkgToPkgKey() where appropriate.
Browse files Browse the repository at this point in the history
  • Loading branch information
skh committed Oct 5, 2020
1 parent d2fef88 commit df23d82
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
RegistryVarsEntry,
} from '../../../../common/types';
import { PackageInvalidArchiveError, PackageUnsupportedMediaTypeError } from '../../../errors';
import { pkgToPkgKey } from '../registry';
import { cacheGet, cacheSet, setArchiveFilelist } from '../registry/cache';
import { unzipBuffer, untarBuffer, ArchiveEntry } from '../registry/extract';

Expand Down Expand Up @@ -110,7 +111,8 @@ function parseAndVerifyArchive(paths: string[]): ArchivePackage {
}

// Package name and version from the manifest must match those from the toplevel directory
if (toplevelDir !== `${manifest.name}-${manifest.version}`) {
const pkgKey = pkgToPkgKey({ name: manifest.name, version: manifest.version });
if (toplevelDir !== pkgKey) {
throw new PackageInvalidArchiveError(
`Name ${manifest.name} and version ${manifest.version} do not match top-level directory ${toplevelDir}`
);
Expand Down Expand Up @@ -147,11 +149,12 @@ function parseAndVerifyDatasets(
// A data stream is made up of a subdirectory of name-version/data_stream/, containing a manifest.yml
let dataStreamPaths: string[] = [];
const dataStreams: RegistryDataStream[] = [];
const pkgKey = pkgToPkgKey({ name: pkgName, version: pkgVersion });

// pick all paths matching name-version/data_stream/DATASTREAM_PATH/...
// from those, pick all unique data stream paths
paths
.filter((path) => path.startsWith(`${pkgName}-${pkgVersion}/data_stream/`))
.filter((path) => path.startsWith(`${pkgKey}/data_stream/`))
.forEach((path) => {
const parts = path.split('/');
if (parts.length > 2 && parts[2]) dataStreamPaths.push(parts[2]);
Expand All @@ -160,7 +163,7 @@ function parseAndVerifyDatasets(
dataStreamPaths = uniq(dataStreamPaths);

dataStreamPaths.forEach((dataStreamPath) => {
const manifestFile = `${pkgName}-${pkgVersion}/data_stream/${dataStreamPath}/manifest.yml`;
const manifestFile = `${pkgKey}/data_stream/${dataStreamPath}/manifest.yml`;
const manifestBuffer = cacheGet(manifestFile);
if (!paths.includes(manifestFile) || !manifestBuffer) {
throw new PackageInvalidArchiveError(
Expand Down

0 comments on commit df23d82

Please sign in to comment.