Skip to content

Commit

Permalink
Updated package installation stream handling (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
andersevenrud committed Apr 11, 2020
1 parent a63d2bf commit c926aa8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
9 changes: 5 additions & 4 deletions src/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ class Packages {
* Loads all packages
* @return {Promise<Package[]>}
*/
createLoader() {
async createLoader() {
let result = [];
const {discoveredFile, manifestFile} = this.options;
const discovered = readOrDefault(discoveredFile);
const manifest = readOrDefault(manifestFile);
const discovered = await readOrDefault(discoveredFile);
const manifest = await readOrDefault(manifestFile);
const sources = discovered.map(d => path.join(d, 'metadata.json'));

logger.info('Using package discovery file', relative(discoveredFile));
Expand Down Expand Up @@ -204,6 +204,7 @@ class Packages {
const target = await realpath(`${userRoot}/${name}`, user);

if (await fs.exists(target)) {
// FIXME: Secure this
await fs.remove(target);
await this.writeUserManifest(userRoot, user);
} else {
Expand All @@ -226,7 +227,7 @@ class Packages {
// TODO: Check conflicts ?
const root = await realpath(userRoot, user);
const manifest = await realpath(`${userRoot}/metadata.json`, user);
const filenames = await fg(root + '/*/metadata.json'); // FIXME: Windows!
const filenames = await fg(root.replace(/\\/g, '/') + '/*/metadata.json');
const metadatas = await Promise.all(filenames.map(f => fs.readJson(f)));

await fs.writeJson(manifest, metadatas);
Expand Down
12 changes: 6 additions & 6 deletions src/utils/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ const fetchSteam = (url, options) => bent()(url, null, {
headers: options.headers || {}
});

const readOrDefault = filename => fs.existsSync(filename)
? fs.readJsonSync(filename)
: [];
const readOrDefault = async (filename) => await fs.exists(filename)
? fs.readJson(filename)
: Promise.resolve([]);

const extract = (stream, target) => new Promise((resolve, reject) => {
stream.once('end', () => resolve());
stream.once('error', error => reject(error));
stream.pipe(tar.extract({C: target}));
const s = stream.pipe(tar.extract({C: target}));
s.once('end', () => resolve());
s.once('error', error => reject(error));
});

module.exports = {
Expand Down

0 comments on commit c926aa8

Please sign in to comment.