Upload into temporary file; Rename it after upload was finished

This commit is contained in:
Ollo 2022-01-06 16:46:33 +01:00
parent 40fce7763e
commit f35da0a3c8

View File

@ -78,9 +78,8 @@ def main(nodeip, luafile, volatile=None, outfile=None):
outfile=luafile outfile=luafile
else: else:
print "Flashing " + luafile + " as " + outfile print "Flashing " + luafile + " as " + outfile
sendCmd(s, "file.remove(\"" + outfile +"\");", True)
sendCmd(s, "w= file.writeline", True) sendCmd(s, "w= file.writeline", True)
sendCmd(s, "file.open(\"" + outfile + "\",\"w+\");", True) sendCmd(s, "file.open(\"temp.lua\",\"w+\");", True)
else: else:
print "Executing " + luafile + " on nodemcu" print "Executing " + luafile + " on nodemcu"
@ -115,6 +114,11 @@ def main(nodeip, luafile, volatile=None, outfile=None):
print "Cannot close the file" print "Cannot close the file"
sys.exit(4) sys.exit(4)
sendCmd(s, "file.remove(\"" + outfile +"\");", True)
if (not sendCmd(s, "file.rename(\"temp.lua\",\""+ outfile + "\")")):
print "Cannot move temporary file to " + outfile
# Check if the file exists: # Check if the file exists:
if (not sendRecv(s, "=file.exists(\"" + outfile + "\")", "true")): if (not sendRecv(s, "=file.exists(\"" + outfile + "\")", "true")):
print("Cannot send " + outfile + " to the ESP") print("Cannot send " + outfile + " to the ESP")