]> Creatis software - creaImageIO.git/blobdiff - src2/creaImageIOTreeHandlerImageAdder.cpp
clean-up
[creaImageIO.git] / src2 / creaImageIOTreeHandlerImageAdder.cpp
index f0f5bf39dbda6e8c3a3fa79645057df8fefe01bd..290da65474741d59812ad591a705f3445e1601e6 100644 (file)
@@ -48,19 +48,23 @@ namespace creaImageIO
        
     unsigned int nbf = filenames.size(); 
     std::vector<std::string>::const_iterator i;
+       mSynchronizer->GetList();
     for (i=filenames.begin();i!=filenames.end();++i)
       {
-       mTimestampHandler->AddFile((*i), fs::last_write_time(*i), time(0),mCurrentDB);
+       
        mProgress.IncNumberScannedFiles();
        if (IsHandledFile(*i)) 
          {
            mProgress.IncNumberHandledFiles();
-               mSynchronizer->InsertAddOp((*i),"0","1",mCurrentDB);
-               std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",(*i),mCurrentDB);
-               std::stringstream removedOn;
-               removedOn<<time(0);
-               mSynchronizer->InsertIgnoreFile(addKey,(*i),"0",removedOn.str(),mCurrentDB);
-           AddFile(*i);
+               if(mSynchronizer->isIndexed(*i))
+               {
+                       mSynchronizer->InsertAddOp((*i),"0","1",mCurrentDB);
+                       std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",(*i),mCurrentDB);
+                       std::stringstream removedOn;
+                       removedOn<<time(0);
+                       mSynchronizer->InsertIgnoreFile(addKey,(*i),"0",removedOn.str(),mCurrentDB);
+                       AddFile(*i);
+               }
          }
        mProgressSignal(mProgress);
        if (mProgress.GetStop()) break;
@@ -80,6 +84,7 @@ namespace creaImageIO
        mSynchronizer->InsertAddOp(directory,rec.str(),"0",mCurrentDB);
        std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",directory,mCurrentDB);
        mTreeHandler->BeginTransaction();
+       mSynchronizer->GetList();
        AddDirectoryRecursor( directory, recurse, addKey );
        
        int nFiles=GetProgress().GetNumberAddedFiles();
@@ -161,6 +166,7 @@ namespace creaImageIO
          }
   }
 
   //=====================================================================
   void TreeHandlerImageAdder::AddDirectoryRecursor(const std::string &dirpath, 
                                                   bool recursive,
@@ -172,11 +178,12 @@ namespace creaImageIO
     if ( !fs::exists( dirpath ) ) return;
        time_t lastModif=fs::last_write_time(dirpath);
 
+       
     fs::directory_iterator end_itr; // default construction yields past-the-end
     for ( fs::directory_iterator itr( dirpath );
          itr != end_itr;
          ++itr )
-      {
+       {
        // If is directory & recurse : do recurse
        if ( fs::is_directory(itr->status()) )
          {
@@ -188,7 +195,8 @@ namespace creaImageIO
        else 
          {
                std::string parent_id;
-               bool valid=mTimestampHandler->AddDirectory(dirpath, itr->string(), lastModif, time(0),mCurrentDB);
+               // tTest if directory (and only it) exists or not.
+               bool valid = mSynchronizer->isIndexed(itr->string());//true;//=mTimestampHandler->AddDirectory(dirpath, itr->string(), lastModif, time(0),mCurrentDB);
                if(valid)
                {
                        mProgress.IncNumberScannedFiles();
@@ -197,7 +205,6 @@ namespace creaImageIO
                        mProgress.IncNumberHandledFiles();
                        AddFile( itr->string() );
                        mTreeHandler->GetTopLevelNodeId("FullFileName",itr->string(),parent_id);
-                       mTimestampHandler->SetAttribute("TopLevelNodeId",parent_id,"PATH",itr->string());
                        std::stringstream removedOn;
                        removedOn<<time(0);
                        mSynchronizer->InsertIgnoreFile(addKey, itr->string(),"0",removedOn.str(),mCurrentDB);
@@ -211,7 +218,6 @@ namespace creaImageIO
                        }
                        
                }
-               mTimestampHandler->SetAttribute("TopLevelNodeId",parent_id,"PATH",dirpath);
          }
       }
        
@@ -352,7 +358,6 @@ namespace creaImageIO
                        //For the new files, add them
                        for (i=newFiles.begin();i!=newFiles.end();++i)
                        {
-                       mTimestampHandler->AddFile((*i), fs::last_write_time(*i), time(0),mCurrentDB);
                        if (IsHandledFile(*i)) 
                        {
                                std::stringstream removedOn;
@@ -412,7 +417,7 @@ namespace creaImageIO
           std::string databaseVal;
           mTreeHandler->GetAttribute("Image","FullFileName",file,a->GetKey(),databaseVal);
           std::string fileVal=attr.find(a->GetKey())->second;
-          if ( a->GetFlags()==0 && databaseVal.compare(fileVal)!=0 
+          if ( a->GetFlags()==0 && databaseVal == fileVal
            {
                        if(repair)
                        {
@@ -487,17 +492,14 @@ namespace creaImageIO
          if(!boost::filesystem::exists(directory))
          {
          boost::filesystem::create_directory(boost::filesystem::path(directory));
-         mTimestampHandler->AddDirectory("",directory,fs::last_write_time(directory)+10, time(0),mCurrentDB);
          mSynchronizer->InsertAddOp(directory,"0","0",mCurrentDB);
          }
          std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",directory,mCurrentDB);
-         std::string parent_id=mTimestampHandler->IsIndexed(directory,mCurrentDB);
          size_t last;
          std::vector<std::string> newNames;
          for(i=filenames.begin();i!=filenames.end();++i)
          {
                  std::string dir=directory.c_str();
-                 mTimestampHandler->CleanPath(dir);
                  if(boost::filesystem::exists(*i) && (*i).find(dir)==std::string::npos)
                  {
                  std::string path=*i;
@@ -514,19 +516,11 @@ namespace creaImageIO
                          p++;
                  }
                  std::string result=out.str();
-                 mTimestampHandler->CleanPath(result);
                  boost::filesystem::copy_file((*i),result);
 
                  //To update image database
                  mTreeHandler->SetAttribute("Image","FullFileName",result,"FullFileName", (*i));
                  
-                 //To update timestamp database
-                 mTimestampHandler->SetAttribute("PATH",result,"PATH",(*i));
-                 mTimestampHandler->SetAttribute("PARENT_ID",parent_id,"PATH",result);
-                 std::stringstream t;
-                 t<<fs::last_write_time(directory)+10;
-                 mTimestampHandler->SetAttribute("LastModified",t.str(),"PATH",result);
-
                  //To update maintenance database
                  //1.Add the new path and increase number of children on new operation.
                  std::stringstream removedOn;
@@ -580,9 +574,6 @@ namespace creaImageIO
 
   void TreeHandlerImageAdder::DeleteDriveFromOtherDB(const std::string& drive)
   {
-         //Delete from timestamp
-         mTimestampHandler->RemoveEntries("FILES", "PATH", "LIKE", drive+"%");
-
          //Delete from maintenance
          mSynchronizer->RemoveEntries("ADD_OPS", "PATH", "LIKE", drive+"%");
          mSynchronizer->RemoveEntries("IGNORED_FILES", "PATH", "LIKE", drive+"%");