From 065387ede564ea9b2bdb6d1a63e43e8e636eaad3 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Thu, 13 Aug 2009 09:06:36 +0000 Subject: Don't try to rebuild the index when the layout has just been created. --- diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py index 0307046..2cda1e9 100644 --- a/src/carquinyol/datastore.py +++ b/src/carquinyol/datastore.py @@ -59,10 +59,10 @@ class DataStore(dbus.service.Object): layout_manager = layoutmanager.get_instance() if layout_manager.get_version() == 0: migration.migrate_from_0() - layout_manager.set_version(2) + layout_manager.set_version(layout_manager.CURRENT_LAYOUT_VERSION) layout_manager.index_updated = False elif layout_manager.get_version() == 1: - layout_manager.set_version(2) + layout_manager.set_version(layout_manager.CURRENT_LAYOUT_VERSION) layout_manager.index_updated = False self._metadata_store = MetadataStore() 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(): -- cgit v0.9.1