Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix “Update all apps” #451

Merged
merged 3 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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