Skip to content

Commit

Permalink
Check for valid package installation archive (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
andersevenrud committed Apr 11, 2020
1 parent 8eb10b8 commit 7d1d170
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ class Packages {
const name = path.basename(url.split('?')[0])
.replace(/\.[^/.]+$/, '');

const stream = await bent()(url, null, {
headers: options.headers || {}
});

const userRoot = options.root || 'home:/.packages'; // FIXME: Client-side
const target = await realpath(`${userRoot}/${name}`, user);
const root = await realpath(userRoot, user);
Expand All @@ -178,10 +174,23 @@ class Packages {
throw new Error('System packages not yet implemented');
}

const stream = await bent()(url, null, {
headers: options.headers || {}
});

await fs.mkdir(target);
await extract(stream, target);

const filenames = await fg(root + '/*/metadata.json');
// FIXME: npm packages have a 'package' subdirectory
if (!await fs.exists(path.resolve(target, 'metadata.json'))) {
await fs.unlink(target);

throw new Error('Invalid package');
}

// TODO: Check conflicts ?

const filenames = await fg(root + '/*/metadata.json'); // FIXME: Windows!
const metadatas = await Promise.all(filenames.map(f => fs.readJson(f)));

await fs.writeJson(manifest, metadatas);
Expand Down

0 comments on commit 7d1d170

Please sign in to comment.