Skip to content

Commit

Permalink
Append to existing apps.json preload state instead of overwriting
Browse files Browse the repository at this point in the history
If the image we are preloading to contains an existing `apps.json` append
the preloaded app to it instead of overwriting it.

Fixes balena-io/balena-cli#2262

Change-type: patch
Signed-off-by: Alex Gonzalez <[email protected]>
  • Loading branch information
alexgg committed May 7, 2021
1 parent 29411df commit 08bff28
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/preload.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,17 @@ def write_resin_device_pinning(app_data, output):


def write_apps_json(data, output):
"""Writes data dict to output as json"""
"""Updates or creates preloaded state"""
if os.path.isfile(output):
with open(output, "r") as f:
current_state = json.load(f)
for uuid in data.keys():
if len(uuid) != len(current_state.keys()[0]):
raise Exception("Current and target preloaded states not "
"compatible")
if uuid not in current_state['apps']:
current_state['apps'][uuid] = data[uuid]
data = current_state
with open(output, "w") as f:
json.dump(data, f, indent=4, sort_keys=True)

Expand Down

0 comments on commit 08bff28

Please sign in to comment.