config-tools: fix bug for saving files

The clean scripts function is a async function, it may run after saving
launch scripts and remove all the launch scripts by accident.
So, add '.then' to make it work as a sync function.

Tracked-On: #7641
Signed-off-by: Conghui <conghui.chen@intel.com>
This commit is contained in:
Conghui 2022-05-31 13:57:49 +08:00 committed by acrnsi-robot
parent f6f8a23df1
commit 1b7e8e393f

View File

@ -276,7 +276,7 @@ export default {
}) })
}, },
cleanLaunchScript() { cleanLaunchScript() {
configurator.readDir(this.WorkingFolder, false) return configurator.readDir(this.WorkingFolder, false)
.then((files) => { .then((files) => {
if (files.length > 0) { if (files.length > 0) {
for (let i = 0; i < files.length; i++) { for (let i = 0; i < files.length; i++) {
@ -382,6 +382,7 @@ export default {
} }
let errorFlag = false let errorFlag = false
errorFlag = this.confirmVmName() errorFlag = this.confirmVmName()
if (errorFlag) {return}
this.assignVMID() this.assignVMID()
let msg = [ let msg = [
"scenario xml saved\n", "scenario xml saved\n",
@ -411,34 +412,38 @@ export default {
totalMsg = totalMsg - 1 // remove the 'launch script' related mssage. totalMsg = totalMsg - 1 // remove the 'launch script' related mssage.
} }
// begin write down and verify // begin write down and verify
try {
configurator.writeFile(this.WorkingFolder + 'scenario.xml', scenarioXMLData)
.then(() => {
stepDone = 1
if (!errorFlag) {
console.log("validate settings...")
this.errors = configurator.pythonObject.validateScenario(this.board.content, scenarioXMLData)
// noinspection ExceptionCaughtLocallyJS
if (this.errors.length !== 0) {
throw new Error("validation failed")
}
console.log("validation ok")
stepDone = 2
this.cleanLaunchScript()
if (needSaveLaunchScript) {
let launchScripts = configurator.pythonObject.generateLaunchScript(this.board.content, scenarioXMLData)
for (let filename in launchScripts) {
configurator.writeFile(this.WorkingFolder + filename, launchScripts[filename])
}
stepDone = 3
}
}
}) configurator.writeFile(this.WorkingFolder + 'scenario.xml', scenarioXMLData)
.then(() => { .then(() => {
alert(`${msg.slice(0, stepDone).join('')} \nAll files successfully saved to your working folder ${this.WorkingFolder}`) stepDone = 1
}) console.log("validate settings...")
} catch (err) { this.errors = configurator.pythonObject.validateScenario(this.board.content, scenarioXMLData)
// noinspection ExceptionCaughtLocallyJS
if (this.errors.length !== 0) {
throw new Error("validation failed")
}
console.log("validation ok")
stepDone = 2
return this.cleanLaunchScript()
}).then(() => {
if (needSaveLaunchScript) {
let launchScripts = configurator.pythonObject.generateLaunchScript(this.board.content, scenarioXMLData)
let writeDone = []
for (let filename in launchScripts) {
writeDone.push(configurator.writeFile(this.WorkingFolder + filename, launchScripts[filename]))
}
return Promise.all(writeDone)
} else {
return
}
})
.then((result) => {
if (!_.isEmpty(result)) {
stepDone = 3
}
alert(`${msg.slice(0, stepDone).join('')} \nAll files successfully saved to your working folder ${this.WorkingFolder}`)
})
.catch((err)=>{
console.log("error" + err) console.log("error" + err)
let outmsg = '' let outmsg = ''
for (var i = 0; i < stepDone; i++) for (var i = 0; i < stepDone; i++)
@ -446,10 +451,9 @@ export default {
for (i = stepDone; i < totalMsg; i++) for (i = stepDone; i < totalMsg; i++)
outmsg += errmsg[i] outmsg += errmsg[i]
alert(`${outmsg} \n Please check your configuration`) alert(`${outmsg} \n Please check your configuration`)
} })
} }
} }
} }
</script> </script>