Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
use tempdir
Browse files Browse the repository at this point in the history
Signed-off-by: James Wallis <[email protected]>
  • Loading branch information
James Wallis authored and elsony committed Jul 30, 2020
1 parent c845af8 commit c60b1fd
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/pfe/portal/modules/utils/installExtensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ const defaultExtensionsDir = '/extensions';
const extensionsPattern = /^(\S+)-(\d+\.\d+\.\d+|latest)\.zip$/; // e.g. extension-name-0.0.1.zip
const versionPattern = /^\d+[.]\d+[.]\d+$/; // e.g. 0.0.1
const SUFFIX_OLD = '__old';
const odoExtensionName = "codewind-odo-extension";
const odoDevfileExtensionName = "codewind-odo-extension-devfile";
const odoExtensionNamePrefix = "codewind-odo";

/**
* Install (unzip) built-in extensions that are stored in /extensions to the
Expand Down Expand Up @@ -59,13 +58,13 @@ async function installBuiltInExtension(file, targetDir, extensionsDir) {
const version = match[2];
log.trace(`extensionPattern - name: ${name}, version ${version}`);

if (([odoExtensionName, odoDevfileExtensionName].includes(name)) && (process.env.ON_OPENSHIFT != 'true')) {
if (name.startsWith(odoExtensionNamePrefix) && (process.env.ON_OPENSHIFT != 'true')) {
return;
}

const source = path.join(extensionsDir, file.name);
const target = path.join(targetDir, name);
const directoryToUnzipTo = `temp_${target}`;
const directoryToUnzipTo = `${target}_temp`;

try {
if (await prepForUnzip(target, version)) {
Expand All @@ -76,7 +75,8 @@ async function installBuiltInExtension(file, targetDir, extensionsDir) {

// Move unzipped files up a directory and to their final name
const [parentDirFromZip] = await fs.readdir(directoryToUnzipTo);
await fs.rename(path.join(directoryToUnzipTo, parentDirFromZip), target);
const tempDir = path.join(directoryToUnzipTo, parentDirFromZip);
await fs.rename(tempDir, target);
}
}
catch (err) {
Expand Down

0 comments on commit c60b1fd

Please sign in to comment.