Skip to content

Commit

Permalink
firmware update validation fix (major!) after refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
suculent committed May 8, 2022
1 parent f9934b9 commit 70f9679
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
26 changes: 22 additions & 4 deletions _envi.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"note": "This is a sample THiNX mock data specification (supported features)",
"oid": "4f1122fa074af4dabab76a5205474882c82de33f50ecd962d25d3628cd0603be",
"oid": "07cef9718edaad79b3974251bb5ef4aedca58703142e8c4c48c20f96cda4979c",
"udid": "d6ff2bb0-df34-11e7-b351-eb37822aa172",
"mac": "11:11:11:11:11:11",
"version": "1.7.2",
"sid": "7038e0500a8690a8bf70d8470f46365458798011e8f46ff012f12cbcf898b2f4",
"ak_failing": "adee16a3d627fc775a8a5e325cf67e57c58b38b6ab9deeef5cb4a47dcded5b7e",
"ak": "adee16a3d627fc775a8a5e325cf67e57c58b38b6ab9deeef5cb4a47dcded5b7e",
"ak": "a6d548c60da8307394d19894a246c9e9eec6c841b8ad54968e047ce0a1687b94",
"build_id": "b1fb3850-de84-11e7-87b3-2d28e305da6d",
"email": "[email protected]",
"test_info": {
Expand All @@ -18,12 +17,31 @@
},
"goals": [],
"username": "cimrman",
"owner": "4f1122fa074af4dabab76a5205474882c82de33f50ecd962d25d3628cd0603be",
"owner": "07cef9718edaad79b3974251bb5ef4aedca58703142e8c4c48c20f96cda4979c",
"email": "[email protected]",
"transformers": [{
"ufid": "vt:b688d51871191b9f645678b10ce70ec23704ef5c549019b8beeaec9939401755",
"alias": "Empty",
"body": "var transformer = function(status, device) { return status };"
}]
},
"test_avatar": "<no-image>",
"dynamic": {
"first_name": "Dynamic",
"last_name": "User",
"email": "[email protected]",
"username": "dynamic",
"udid": "d6ff2bb0-df34-11e7-b351-eb37822aa174",
"owner": "bab692f8c9c78cf64f579406bdf6c6cd2c4d00b3c0c8390387d051495dd95247",
"transformers": [{
"ufid": "vt:b688d51871191b9f645678b10ce70ec23704ef5c549019b8beeaec9939401756",
"alias": "Empty",
"body": "var transformer = function(status, device) { return status };"
}]
},
"dynamic2": {
"owner": "40e8a98eee1855695bea07f83726fc474ad5681b003610fc38d9ff8b891e9b42",
"email": "[email protected]"
}

}
22 changes: 13 additions & 9 deletions lib/thinx/deployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ module.exports = class Deployment {
// check if any build exists for this device
if (!fs.existsSync(path)) { // lgtm [js/path-injection]
console.log("☣️ [error] LFE path does not exist.");
return false;
return false;
}

var envpath = path + "/build.json";
if (fs.existsSync(envpath)) { // lgtm [js/path-injection]
return JSON.parse(fs.readFileSync(envpath)); // lgtm [js/path-injection]
Expand Down Expand Up @@ -326,10 +326,12 @@ module.exports = class Deployment {
var dpath = this.pathForDevice(owner, udid);
var fpath = dpath + "/" + build_id + "/" + build_id + ".zip";
let data = null;
try {
fs.readFileSync(fpath);
} catch (e) {
console.log("[error] caught exception", e, "while reading artifact at", fpath);
if (fs.existsSync(fpath)) {
try {
fs.readFileSync(fpath);
} catch (e) {
console.log("[error] caught exception", e, "while reading artifact at", fpath);
}
}
return data; // lgtm [js/path-injection]
}
Expand Down Expand Up @@ -357,6 +359,8 @@ module.exports = class Deployment {
console.log("☣️ [error] [validateHasUpdateAvailable] Device does not support updates.");
return false;
}

return true;
}

hasUpdateAvailable(device) {
Expand All @@ -376,8 +380,8 @@ module.exports = class Deployment {
if (outdated) {
console.log("ℹ️ [info] Device has:", deviceVersion, ", update available to:", available_version);
return true;
}
}

// Device version same, but environment may change
if (semver.eq(deviceVersion, available_version)) {
// versions equal, update may happen
Expand All @@ -397,7 +401,7 @@ module.exports = class Deployment {
} else {
console.log("ℹ️ [info] Device version is newer than available.");
}

return outdated;
}
};

0 comments on commit 70f9679

Please sign in to comment.