Don't delete InternetGatewayDevice tree when reinitializing device

This commit is contained in:
Zaid Abdulla committed 2013-07-22 20:32:32 +03:00
1 parent 8167c0c6e5
commit bcfd56d868
2 files changed
+18 -16

No files matched your search

+3 -5
View File
@@ -117,11 +117,9 @@ updateDevice = (currentRequest, actions, callback) ->
) )
else if updates['_lastBootstrap']? else if updates['_lastBootstrap']?
# reinitialize on bootstrap event (e.g. firmware upgrade) # reinitialize on bootstrap event (e.g. firmware upgrade)
db.devicesCollection.update({'_id' : currentRequest.deviceId}, {'$unset' : 'InternetGatewayDevice'}, {safe: true}, (err, count) -> task = {device : currentRequest.deviceId, name : 'init', timestamp : config.INIT_TIMESTAMP}
task = {device : currentRequest.deviceId, name : 'init', timestamp : config.INIT_TIMESTAMP} apiFunctions.insertTasks(task, (err) ->
apiFunctions.insertTasks(task, (err) -> callback(err) if callback?
callback(err) if callback?
)
) )
else else
callback() if callback? callback() if callback?
+15 -11
View File
@@ -108,21 +108,25 @@ this.getParameterNames = (task, methodResponse, callback) ->
deviceUpdates = {parameterNames : methodResponse.parameterList} deviceUpdates = {parameterNames : methodResponse.parameterList}
path = if common.endsWith(task.parameterPath, '.') then task.parameterPath.slice(0, -1) else task.parameterPath path = if common.endsWith(task.parameterPath, '.') then task.parameterPath.slice(0, -1) else task.parameterPath
projection = {} projection = {}
projection[path] = 1 projection[path] = 1 if !!task.parameterPath
# delete nonexisting params # delete nonexisting params
db.devicesCollection.findOne({_id : task.device}, projection, (err, device) -> db.devicesCollection.findOne({_id : task.device}, projection, (err, device) ->
if device if device
root = device if !!task.parameterPath
rootPath = '' root = device
ps = path.split('.') rootPath = ''
for p in ps ps = path.split('.')
if root[p]? for p in ps
root = root[p] if root[p]?
rootPath += "#{p}." root = root[p]
else rootPath += "#{p}."
root = null else
break root = null
break
else
root = device['InternetGatewayDevice']
rootPath = 'InternetGatewayDevice.'
if root if root
deviceUpdates.deletedObjects = [] deviceUpdates.deletedObjects = []