Skip to content

Commit

Permalink
Merge pull request #451 from NordicSemiconductor/fix_update_all_apps
Browse files Browse the repository at this point in the history
Fix “Update all apps”
  • Loading branch information
datenreisender authored Aug 3, 2020
2 parents b810ef7 + c29c456 commit abaa1e4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Version 3.4.2
### Fixes
- “Update all apps” sometimes showed an error message (even though it worked
correctly). #451

## Version 3.4.1
### Updates
- Updated to pc-nrfjprog-js v1.7.3, including bundled nrfjprog v10.9.0 and JLink 6.80a
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nrfconnect",
"version": "3.4.1",
"version": "3.4.2",
"description": "nRF Connect for PC",
"repository": {
"type": "git",
Expand Down
10 changes: 7 additions & 3 deletions src/main/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function installLocalAppArchive(tgzFilePath) {
.then(isInstalled => {
if (!isInstalled) {
return fileUtil.mkdir(appPath)
.then(() => fileUtil.extractNpmPackage(tgzFilePath, appPath))
.then(() => fileUtil.extractNpmPackage(appName, tgzFilePath, appPath))
.then(() => fileUtil.deleteFile(tgzFilePath));
}
return Promise.resolve();
Expand Down Expand Up @@ -490,7 +490,11 @@ function removeOfficialApp(name, source) {
+ `to remove app directory ${appPath}. The directory does not `
+ 'have node_modules in its path.'));
}
return fs.remove(appPath);

const tmpDir = fileUtil.getTmpFilename(name);

return fs.move(appPath, tmpDir)
.then(() => fs.remove(tmpDir));
}

/**
Expand All @@ -513,7 +517,7 @@ function installOfficialApp(name, version, source) {
}
return Promise.resolve();
})
.then(() => fileUtil.extractNpmPackage(tgzFilePath, appPath))
.then(() => fileUtil.extractNpmPackage(name, tgzFilePath, appPath))
.then(() => fileUtil.deleteFile(tgzFilePath));
});
}
Expand Down
26 changes: 23 additions & 3 deletions src/main/fileUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ const fse = require('fs-extra');
const path = require('path');
const targz = require('targz');
const chmodr = require('chmodr');
const { v4 } = require('uuid');
const { mkdir, mkdirIfNotExists } = require('./mkdir');
const config = require('./config');

/**
* Open the given file path and return its string contents.
Expand Down Expand Up @@ -228,15 +230,33 @@ function chmodDir(src, mode) {
});
}

/**
* Create a unique name for a temporary file or folder. The file is not
* created, this just generates an absolute name for it in the directory
* for temporary files.
*
* @param {string} basename a basename to include in the name to make it easier
* to recognise
* @returns {string} the unique file name
*/
function getTmpFilename(basename) {
return path.join(config.getTmpDir(), `${basename}-${v4()}`);
}

/**
* Extract the given npm package (tgz file) to the given destination directory.
*
* @param {string} appName the name of the app to extract
* @param {string} tgzFile the tgz file path to extract.
* @param {string} destinationDir the destination directory.
* @returns {Promise} promise that resolves if successful.
*/
function extractNpmPackage(tgzFile, destinationDir) {
return untar(tgzFile, destinationDir, 1);
function extractNpmPackage(appName, tgzFile, destinationDir) {
const tmpDir = getTmpFilename(appName);
const moveToDestinationDir = () => fse.move(tmpDir, destinationDir, { overwrite: true });

return untar(tgzFile, tmpDir, 1)
.then(moveToDestinationDir);
}

/**
Expand Down Expand Up @@ -288,7 +308,6 @@ function createJsonFileIfNotExists(filePath, jsonData) {
}

module.exports = {
readFile,
readJsonFile,
listDirectories,
listFiles,
Expand All @@ -297,6 +316,7 @@ module.exports = {
copy,
untar,
chmodDir,
getTmpFilename,
extractNpmPackage,
getNameFromNpmPackage,
mkdir,
Expand Down

0 comments on commit abaa1e4

Please sign in to comment.