For the first time dispatcher test is working... though there is still
some instability with sqlite3. Sometimes complains about "Library
routine called out of sequence" when writing...
diff --git a/src/dispatcher.cc b/src/dispatcher.cc
index 556144f..1775ca2 100644
--- a/src/dispatcher.cc
+++ b/src/dispatcher.cc
@@ -254,9 +254,11 @@
       if (m_objectDbMap.find (hash) == m_objectDbMap.end ())
         {
           _LOG_DEBUG ("create ObjectDb for " << hash);
-          m_objectDbMap [hash] = make_shared<ObjectDb> (m_rootDir, lexical_cast<string> (hash));
+          m_objectDbMap [hash] = make_shared<ObjectDb> (m_rootDir / ".chronoshare", lexical_cast<string> (hash));
         }
 
+      _LOG_DEBUG ("dafaq: " << (m_objectDbMap.find (hash) == m_objectDbMap.end ()));
+
       m_fileFetcher->Enqueue (deviceName, fileNameBase,
                               bind (&Dispatcher::Did_FetchManager_FileSegmentFetch, this, _1, _2, _3, _4),
                               bind (&Dispatcher::Did_FetchManager_FileFetchComplete, this, _1, _2),
@@ -325,6 +327,16 @@
   const Bytes &hashBytes = fileBaseName.getCompFromBack (0);
   Hash hash (head (hashBytes), hashBytes.size ());
 
+  if (m_objectDbMap.find (hash) != m_objectDbMap.end())
+  {
+    // remove the db handle
+    m_objectDbMap.erase (hash); // to commit write
+  }
+  else
+  {
+    _LOG_ERROR ("no db available for this file: " << hash);
+  }
+
   FileItemsPtr filesToAssemble = m_actionLog->LookupFilesForHash (hash);
 
   for (FileItems::iterator file = filesToAssemble->begin ();
@@ -337,14 +349,4 @@
       last_write_time (filePath, file->mtime ());
       permissions (filePath, static_cast<filesystem::perms> (file->mode ()));
     }
-
-  if (m_objectDbMap.find (hash) != m_objectDbMap.end())
-  {
-    // remove the db handle
-    m_objectDbMap.erase (hash);
-  }
-  else
-  {
-    _LOG_ERROR ("no db available for this file: " << hash);
-  }
 }
diff --git a/src/hash-helper.h b/src/hash-helper.h
index 4224860..ab93697 100644
--- a/src/hash-helper.h
+++ b/src/hash-helper.h
@@ -113,11 +113,16 @@
 
     for (int i = 0; i < m_length; i++)
       {
+        if (m_buf [i] < otherHash.m_buf [i])
+          return true;
+
         if (m_buf [i] > otherHash.m_buf [i])
           return false;
+
+        // if equal, continue
       }
 
-    return true;
+    return false;
   }
 
   const void *
diff --git a/src/object-db.cc b/src/object-db.cc
index fe00225..84c6ae8 100644
--- a/src/object-db.cc
+++ b/src/object-db.cc
@@ -50,6 +50,8 @@
   fs::path actualFolder = folder / "objects" / hash.substr (0, 2);
   fs::create_directories (actualFolder);
 
+  _LOG_DEBUG ("Open " << (actualFolder / hash.substr (2, hash.size () - 2)));
+
   int res = sqlite3_open((actualFolder / hash.substr (2, hash.size () - 2)).c_str (), &m_db);
   if (res != SQLITE_OK)
     {
@@ -65,10 +67,12 @@
   res = sqlite3_exec (m_db, INIT_DATABASE.c_str (), NULL, NULL, &errmsg);
   if (res != SQLITE_OK && errmsg != 0)
     {
-      // std::cerr << "DEBUG: " << errmsg << std::endl;
+      _LOG_DEBUG (errmsg);
       sqlite3_free (errmsg);
     }
 
+  // _LOG_DEBUG ("open db");
+
   willStartSave ();
 }
 
@@ -114,6 +118,7 @@
 {
   didStopSave ();
 
+  // _LOG_DEBUG ("close db");
   int res = sqlite3_close (m_db);
   if (res != SQLITE_OK)
     {
@@ -137,6 +142,7 @@
   sqlite3_bind_blob (stmt, 3, &data[0], data.size (), SQLITE_STATIC);
 
   sqlite3_step (stmt);
+  _LOG_DEBUG ("After saving object: " << sqlite3_errmsg (m_db));
   sqlite3_finalize (stmt);
 }
 
@@ -188,10 +194,12 @@
 ObjectDb::willStartSave ()
 {
   sqlite3_exec (m_db, "BEGIN TRANSACTION;", 0,0,0);
+  // _LOG_DEBUG ("Open transaction: " << sqlite3_errmsg (m_db));
 }
 
 void
 ObjectDb::didStopSave ()
 {
   sqlite3_exec (m_db, "END TRANSACTION;", 0,0,0);
+  // _LOG_DEBUG ("Close transaction: " << sqlite3_errmsg (m_db));
 }