Blob Blame History Raw
From 03c464355460df668631feb0fa7a70c1499306aa Mon Sep 17 00:00:00 2001
From: James Cameron <quozl@laptop.org>
Date: Sat, 2 May 2020 11:38:57 +1000
Subject: [PATCH] Fix DBusException using Moon activity

Moon activity makes multiple datastore API calls within one second, and
the file used to store the data is named by the second of the epoch,
such that one API call clashes with another.

Use a sequence number instead of the second of the epoch.
---
 src/jarabe/apisocket.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/jarabe/apisocket.py b/src/jarabe/apisocket.py
index fc4561716..bcefedf2e 100644
--- a/src/jarabe/apisocket.py
+++ b/src/jarabe/apisocket.py
@@ -16,7 +16,6 @@
 import json
 import os
 import struct
-import time
 import binascii
 
 import dbus
@@ -115,12 +114,14 @@ def __init__(self, client):
                                     "/org/laptop/sugar/DataStore")
         self._data_store = dbus.Interface(bus_object,
                                           "org.laptop.sugar.DataStore")
+        self._sequence = 0
 
     def _create_file(self):
         activity_root = env.get_profile_path(self._activity.get_type())
         instance_path = os.path.join(activity_root, "instance")
 
-        file_path = os.path.join(instance_path, "%i" % time.time())
+        self._sequence += 1
+        file_path = os.path.join(instance_path, "%d" % self._sequence)
         file_object = open(file_path, "w")
 
         return file_path, file_object