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: close file connections before updating the server #1172

Merged
merged 1 commit into from
Oct 28, 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
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 @@ -54,7 +55,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 @@ -298,6 +299,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