diff options
Diffstat (limited to 'src/carquinyol/layoutmanager.py')
-rw-r--r-- | src/carquinyol/layoutmanager.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/carquinyol/layoutmanager.py b/src/carquinyol/layoutmanager.py index a017029..42db46f 100644 --- a/src/carquinyol/layoutmanager.py +++ b/src/carquinyol/layoutmanager.py @@ -17,7 +17,7 @@ import os MAX_QUERY_LIMIT = 40960 - +CURRENT_LAYOUT_VERSION = 2 class LayoutManager(object): """Provide the logic about how entries are stored inside the datastore @@ -32,13 +32,19 @@ class LayoutManager(object): if not os.path.exists(self._root_path): os.makedirs(self._root_path) - self.set_version(1) self._create_if_needed(self.get_checksums_dir()) self._create_if_needed(self.get_queue_path()) index_updated_path = os.path.join(self._root_path, 'index_updated') - self._index_updated = os.path.exists(index_updated_path) + if os.path.exists(index_updated_path): + self._index_updated = True + elif self._is_empty(): + open(index_updated_path, 'w').close() + self.set_version(CURRENT_LAYOUT_VERSION) + self._index_updated = True + else: + self._index_updated = False def _create_if_needed(self, path): if not os.path.exists(path): @@ -95,6 +101,13 @@ class LayoutManager(object): uids.append(g) return uids + def _is_empty(self): + for f in os.listdir(self._root_path): + if os.path.isdir(os.path.join(self._root_path, f)) and len(f) == 2: + for g in os.listdir(os.path.join(self._root_path, f)): + if len(g) == 36: + return False + return True _instance = None def get_instance(): |