Skip to content

Commit

Permalink
fix: closing file connections before updating the server (#1172)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmotelet authored Oct 28, 2020
1 parent e82e23a commit 38533d7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/interfaces/appstore.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const _ = require('lodash')
const compareVersions = require('compare-versions')
const { installModule, removeModule } = require('../modules')
const {
isTheServerModule,
findModulesWithKeyword,
getLatestServerVersion,
getAuthor
Expand Down Expand Up @@ -55,7 +56,7 @@ module.exports = function(app) {
findPluginsAndWebapps()
.then(([plugins, webapps]) => {
if (
name !== app.config.name &&
!isTheServerModule(name, app) &&
!plugins.find(packageNameIs(name)) &&
!webapps.find(packageNameIs(name))
) {
Expand Down Expand Up @@ -302,6 +303,21 @@ module.exports = function(app) {
}

function installSKModule(module, version) {
if (isTheServerModule(module, app)) {
try {
app.providers.forEach(providerHolder => {
if (
typeof providerHolder.pipeElements[0].pipeline[0].options
.filename !== 'undefined'
) {
debug('close file connection:', providerHolder.id)
providerHolder.pipeElements[0].end()
}
})
} catch (err) {
debug(err)
}
}
updateSKModule(module, version, false)
}

Expand Down
7 changes: 6 additions & 1 deletion src/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function runNpm(

debug(`${command}: ${packageString}`)

if (name === app.config.name) {
if (isTheServerModule(name, app)) {
if (process.platform === 'win32') {
npm = spawn(
'cmd',
Expand Down Expand Up @@ -207,6 +207,10 @@ function runNpm(
})
}

function isTheServerModule(moduleName: string, app: App) {
return moduleName === app.config.name
}

function findModulesWithKeyword(keyword: string) {
return new Promise((resolve, reject) => {
let errorCount = 0
Expand Down Expand Up @@ -325,6 +329,7 @@ module.exports = {
modulesWithKeyword,
installModule,
removeModule,
isTheServerModule,
findModulesWithKeyword,
getLatestServerVersion,
checkForNewServerVersion,
Expand Down

0 comments on commit 38533d7

Please sign in to comment.