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.
@@ -276,7 +276,7 @@ export default {
})
},
cleanLaunchScript() {
- configurator.readDir(this.WorkingFolder, false)
+ return configurator.readDir(this.WorkingFolder, false)
.then((files) => {
if (files.length > 0) {
for (let i = 0; i < files.length; i++) {
@@ -382,6 +382,7 @@ export default {
}
let errorFlag = false
errorFlag = this.confirmVmName()
+ if (errorFlag) {return}
this.assignVMID()
let msg = [
"scenario xml saved\n",
@@ -411,11 +412,10 @@ export default {
totalMsg = totalMsg - 1 // remove the 'launch script' related mssage.
}
// 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
@@ -424,21 +424,26 @@ export default {
}
console.log("validation ok")
stepDone = 2
- this.cleanLaunchScript()
+ return this.cleanLaunchScript()
+ }).then(() => {
if (needSaveLaunchScript) {
let launchScripts = configurator.pythonObject.generateLaunchScript(this.board.content, scenarioXMLData)
+ let writeDone = []
for (let filename in launchScripts) {
- configurator.writeFile(this.WorkingFolder + filename, launchScripts[filename])
- }
- stepDone = 3
+ writeDone.push(configurator.writeFile(this.WorkingFolder + filename, launchScripts[filename]))
}
+ return Promise.all(writeDone)
+ } else {
+ return
}
-
})
- .then(() => {
+ .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) {
+ .catch((err)=>{
console.log("error" + err)
let outmsg = ''
for (var i = 0; i < stepDone; i++)
@@ -446,11 +451,10 @@ export default {
for (i = stepDone; i < totalMsg; i++)
outmsg += errmsg[i]
alert(`${outmsg} \n Please check your configuration`)
+ })
}
}
}
-
-}
</script>
<style scoped>
