Add second fileState to avoid incorrect detection of local modifications

Change-Id: I80fa339ca8922dfb8ca7511a7279fdacb0358c77
diff --git a/src/dispatcher.cc b/src/dispatcher.cc
index 390cb4a..46e0e1b 100644
--- a/src/dispatcher.cc
+++ b/src/dispatcher.cc
@@ -61,6 +61,7 @@
                                        ActionLog::OnFileAddedOrChangedCallback (), // don't really need this callback
                                        bind (&Dispatcher::Did_ActionLog_ActionApply_Delete, this, _1));
   m_fileState = m_actionLog->GetFileState ();
+  m_fileStateCow = make_shared<FileState> (m_rootDir, true);
 
   Name syncPrefix = Name(BROADCAST_DOMAIN)(CHRONOSHARE_APP)(sharedFolder);
 
@@ -206,7 +207,10 @@
       return;
     }
 
-  FileItemPtr currentFile = m_fileState->LookupFile (relativeFilePath.generic_string ());
+  FileItemPtr currentFile = m_fileStateCow->LookupFile (relativeFilePath.generic_string ());
+  if(!currentFile)
+    currentFile = m_fileState->LookupFile (relativeFilePath.generic_string ());
+
   if (currentFile &&
       *Hash::FromFileContent (absolutePath) == Hash (currentFile->file_hash ().c_str (), currentFile->file_hash ().size ())
       // The following two are commented out to prevent front end from reporting intermediate files
@@ -219,13 +223,6 @@
       return;
     }
 
-  if (currentFile &&
-      !currentFile->is_complete ())
-    {
-      _LOG_ERROR ("Got notification about incomplete file [" << relativeFilePath << "]");
-      return;
-    }
-
 
   int seg_num;
   HashPtr hash;
@@ -473,6 +470,12 @@
        file != filesToAssemble->end ();
        file++)
     {
+      m_fileStateCow->UpdateFile (file->filename(), file->version(),
+                                  Hash(file->file_hash ().c_str(), file->file_hash ().size ()), 
+                                  CcnxCharbuf (file->device_name().c_str(), file->device_name().size()), file->seq_no(),
+                                  file->mtime(), file->mtime(), file->mtime(), 
+                                  file->mode(), file->seg_num());
+
       boost::filesystem::path filePath = m_rootDir / file->filename ();
 
       try
@@ -504,6 +507,7 @@
 #endif
 
             m_fileState->SetFileComplete (file->filename ());
+            m_fileStateCow->DeleteFile(file->filename());
           }
         else
           {
diff --git a/src/dispatcher.h b/src/dispatcher.h
index d3b6bc3..d5c0f30 100644
--- a/src/dispatcher.h
+++ b/src/dispatcher.h
@@ -165,6 +165,7 @@
   SyncLogPtr   m_syncLog;
   ActionLogPtr m_actionLog;
   FileStatePtr m_fileState;
+  FileStatePtr m_fileStateCow;
 
   boost::filesystem::path m_rootDir;
   Executor m_executor;
diff --git a/src/file-state.cc b/src/file-state.cc
index d361eb7..fa998de 100644
--- a/src/file-state.cc
+++ b/src/file-state.cc
@@ -52,8 +52,8 @@
 CREATE INDEX FileState_type_file_hash ON FileState (type, file_hash);   \n\
 ";
 
-FileState::FileState (const boost::filesystem::path &path)
-  : DbHelper (path / ".chronoshare", "file-state.db")
+FileState::FileState (const boost::filesystem::path &path, bool cow)
+  : DbHelper (path / ".chronoshare",  (cow ? "file-state-tmp.db" : "file-state.db"))
 {
   sqlite3_exec (m_db, INIT_DATABASE.c_str (), NULL, NULL, NULL);
   _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_OK, sqlite3_errmsg (m_db));
diff --git a/src/file-state.h b/src/file-state.h
index 0a8a7b2..b0890a2 100644
--- a/src/file-state.h
+++ b/src/file-state.h
@@ -41,7 +41,7 @@
 class FileState : public DbHelper
 {
 public:
-  FileState (const boost::filesystem::path &path);
+  FileState (const boost::filesystem::path &path, bool cow = false);
   ~FileState ();
 
   /**