0
0
mirror of https://github.com/Doodle3D/doodle3d-firmware.git synced 2024-06-26 03:21:22 +02:00

Fixes to update module and api.

This commit is contained in:
Wouter R 2013-10-21 13:42:58 +02:00
parent b6528e4752
commit 581ea273b2
2 changed files with 28 additions and 13 deletions

View File

@ -62,20 +62,20 @@ function M.download_POST(request, response)
end
if argClearGcode then
response:addData('gcode_clear',true)
local rv,msg = printer:clearGcode()
response:addData('gcode_clear',true)
local rv,msg = printer:clearGcode()
if not rv then
response:setError(msg)
return
end
if not rv then
response:setError(msg)
return
end
end
vEnt,msg = updater.findVersion(argVersion)
if vEnt == nil then
response:setFail("error searching version index (" .. msg .. ")")
return
else if vEnt == false then
elseif vEnt == false then
response:setFail("no such version")
return
end
@ -99,7 +99,16 @@ function M.install_POST(request, response)
return
end
local rv,msg = updater.flashImageVersion(argVersion)
vEnt,msg = updater.findVersion(argVersion)
if vEnt == nil then
response:setFail("error searching version index (" .. msg .. ")")
return
elseif vEnt == false then
response:setFail("no such version")
return
end
local rv,msg = updater.flashImageVersion(vEnt)
if not rv then response:setFail("installation failed (" .. msg .. ")")
else response:setSuccess()

View File

@ -13,7 +13,7 @@
-- copy improved fileSize back to utils (add unit tests!)
-- create new utils usable by updater as well as api? (remove dependencies on uci and logger etc)
-- note: take care not to print any text in module functions, as this breaks http responses
-- change representation of sysupgrade/factory info in versionInfo? (and also in image index?)
-- change representation of sysupgrade/factory info in versionInfo? (and also in image index?) <- create api call to get all info on all versions?
local M = {}
@ -64,6 +64,7 @@ end
-- splits the return status from os.execute (see: http://stackoverflow.com/questions/16158436/how-to-shift-and-mask-bits-from-integer-in-lua)
local function splitExitStatus(exitStatus)
if exitStatus == -1 then return -1,-1 end
local cmdStatus = math.floor(exitStatus / 256)
local systemStatus = exitStatus - cmdStatus * 256
return cmdStatus, systemStatus
@ -183,7 +184,7 @@ end
-- returns return value of command
local function runCommand(command, dryRun)
D("about to run: '" .. command .. "'")
return (not dryRun) and os.execute(command) or 0
return (not dryRun) and os.execute(command) or -1
end
local function removeFile(filePath)
@ -263,14 +264,18 @@ end
function M.getStatus()
if not baseUrl then baseUrl = M.DEFAULT_BASE_URL end
local unknownVersion = { major = 0, minor = 0, patch = 0 }
local result = {}
local verTable,msg = M.getAvailableVersions()
if not verTable then return nil,msg end
if not verTable then
D("could not obtain available versions (" .. msg .. ")")
-- TODO: set an error state in result to signify we probably do not have internet access?
end
local newest = verTable[#verTable]
local newest = verTable and verTable[#verTable]
result.currentVersion = M.getCurrentVersion()
result.newestVersion = newest and newest.version or { major = 0, minor = 0, patch = 0 }
result.newestVersion = newest and newest.version or unknownVersion
result.stateCode, result.stateText = getState()
result.stateCode = tonumber(result.stateCode)
@ -316,6 +321,7 @@ end
-- verTable is optional, getAvailableVersions will be used to obtain it if nil
function M.findVersion(version, verTable)
local msg = nil
version = M.parseVersion(version)
if not verTable then verTable,msg = M.getAvailableVersions() end
if not verTable then return nil,msg end