Public Member Functions

Dedupe::Core::Kernel Class Reference

Public Member Functions

 Kernel (Dedupe::FilePath DatabaseLocation, size_t Threads, std::ostream &Messages)
void TrackFiles (Dedupe::FilePaths const &Paths, bool recursiv)
void ListDatabase ()
Dedupe::FileStream GetDatabase ()
void UntrackFiles (Dedupe::FilePaths const &Paths, bool recursiv)
Duplicates FindHashDuplicates ()
Duplicates FindHashDuplicatesExtern (Dedupe::FilePaths, bool recursiv)
Duplicates FindFilenameDuplicates ()
Duplicates FindFilenameDuplicatesExtern (Dedupe::FilePaths, bool recursiv)
Duplicates FindFilesizeDuplicates ()
Duplicates FindFilesizeDuplicatesExtern (Dedupe::FilePaths, bool recursiv)
Duplicates FindFiledateDuplicates ()
Duplicates FindFiledateDuplicatesExtern (Dedupe::FilePaths, bool recursiv)
void ProcessDuplicates (FilesToProcess Dups)
void AutoUpdateDatabase ()
void QuitKernel (bool &AmIDead)

Detailed Description

Definition at line 97 of file kernel.h.


Member Function Documentation

void Dedupe::Core::Kernel::AutoUpdateDatabase (  ) 

Call this function to update the database. Should be called after programstart to read in all changes from files on hdd.

Definition at line 347 of file kernel.cpp.

References Dedupe::Dataholding::Dataholding::DelFile(), Dedupe::Dataholding::Dataholding::GetFiles(), Dedupe::Hash::Hash< T >::HashFileInfo(), and Dedupe::Dataholding::Dataholding::UpdateFile().

Referenced by Dedupe::CLI::Cli::Run().

{
  MessageOut << "Starting database update...\n";
  //Get a copy from the Files in the database
  Dedupe::FileStream FilesFromDatabase = Database.GetFiles();
  Dedupe::FileStream FilesToCheck;

  /*Use paths from the stored files to build
    new FileInfos and store them in FilesToCheck*/
  std::for_each( FilesFromDatabase.begin(),
                 FilesFromDatabase.end(),
        [ &FilesToCheck ]( Dedupe::FileInfo Current )
        { FilesToCheck.push_back( Dedupe::FileInfo( Current.GetPath())); });

  size_t i = 0;
  std::for_each( FilesToCheck.begin(),
                 FilesToCheck.end(),
        [ &FilesToCheck, FilesFromDatabase,this,&i ] (Dedupe::FileInfo Current )
        {
          /*if the filestatus is not FileOK delete file from database else
            update the file in database*/
          if( Current.GetStatus() != Dedupe::FileInfo::FileOK )
          {
            MessageOut << "Deleting file from database: "
                       << Current.GetPath() << std::endl;
            Database.DelFile( Current );
          }
          else
          {
            /*Update file only, if something of file has changed,
              but no check for hash*/
            if( !EqualNoHash( Current, FilesFromDatabase[ i ] ))
            {
              MessageOut << "Updating file in database: "
                         << Current.GetPath() << std::endl;
              Hasher.HashFileInfo( Current );
              Database.UpdateFile( Current );
            }
          }
          ++i;
        });

  MessageOut << "Databaseupdate finished.\n";
}

Dedupe::Core::Duplicates Dedupe::Core::Kernel::FindFiledateDuplicates (  ) 

FindFiledateDuplicates searches for duplicates in the database by the filedate.

Returns:
a Duplicates Vector. If the vector is empty no duplicates are found

Definition at line 212 of file kernel.cpp.

References Dedupe::FileInfo::GetDateChanged(), and Dedupe::Dataholding::Dataholding::GetFiles().

Referenced by Dedupe::CLI::Cli::Run().

{
  //we search for duplicates in the database, decide duplicates by filedate
  return FindDuplicates( Database.GetFiles(),
              [](Dedupe::FileInfo lhs, Dedupe::FileInfo rhs )
              { return lhs.GetDateChanged() > rhs.GetDateChanged();},

              [](Dedupe::FileInfo lhs, Dedupe::FileInfo rhs )
              { return lhs.GetDateChanged() == rhs.GetDateChanged();});
}

Dedupe::Core::Duplicates Dedupe::Core::Kernel::FindFiledateDuplicatesExtern ( Dedupe::FilePaths  Paths,
bool  recursiv 
)

FindFiledateDuplicatesExtern searches for duplicates in the given paths by the filedate. Give the start paths and recursive flag.

Returns:
a Duplicates Vector. If the vector is empty no duplicates are found

Definition at line 225 of file kernel.cpp.

References Dedupe::FileInfo::GetDateChanged().

Referenced by Dedupe::CLI::Cli::Run().

{
  //we search for duplicates in the given orders, decide duplicates by filedate
  return FindExternDuplicates( Paths, recursiv,
              [](Dedupe::FileInfo lhs, Dedupe::FileInfo rhs )
              { return lhs.GetDateChanged() > rhs.GetDateChanged();},

              [](Dedupe::FileInfo lhs, Dedupe::FileInfo rhs )
              { return lhs.GetDateChanged() == rhs.GetDateChanged();});
}

Dedupe::Core::Duplicates Dedupe::Core::Kernel::FindFilenameDuplicates (  ) 

FindFilenameDuplicates searches for duplicates in the database by the filename.

Returns:
a Duplicates Vector. If the vector is empty no duplicates are found

Definition at line 160 of file kernel.cpp.

References Dedupe::Dataholding::Dataholding::GetFiles(), and Dedupe::FileInfo::GetPath().

Referenced by Dedupe::CLI::Cli::Run().

{
  //we search for duplicates in the database, decide duplicates by filename
  return FindDuplicates( Database.GetFiles(),
              [](Dedupe::FileInfo lhs, Dedupe::FileInfo rhs )
              { return lhs.GetPath().filename() > rhs.GetPath().filename();},

              [](Dedupe::FileInfo lhs, Dedupe::FileInfo rhs )
              { return lhs.GetPath().filename() == rhs.GetPath().filename();});
}

Dedupe::Core::Duplicates Dedupe::Core::Kernel::FindFilenameDuplicatesExtern ( Dedupe::FilePaths  Paths,
bool  recursiv 
)

FindFilenameDuplicatesExtern searches for duplicates in the given paths by the filename. Give the start paths and recursive flag.

Returns:
a Duplicates Vector. If the vector is empty no duplicates are found

Definition at line 173 of file kernel.cpp.

References Dedupe::FileInfo::GetPath().

Referenced by Dedupe::CLI::Cli::Run().

{
  //we search for duplicates in the given orders, decide duplicates by filename
  return FindExternDuplicates( Paths, recursiv,
              [](Dedupe::FileInfo lhs, Dedupe::FileInfo rhs )
              { return lhs.GetPath().filename() > rhs.GetPath().filename();},

              [](Dedupe::FileInfo lhs, Dedupe::FileInfo rhs )
              { return lhs.GetPath().filename() == rhs.GetPath().filename();});
}

Dedupe::Core::Duplicates Dedupe::Core::Kernel::FindFilesizeDuplicates (  ) 

FindFilesizeDuplicates searches for duplicates in the database by the filesize.

Returns:
a Duplicates Vector. If the vector is empty no duplicates are found

Definition at line 186 of file kernel.cpp.

References Dedupe::Dataholding::Dataholding::GetFiles(), and Dedupe::FileInfo::GetSize().

Referenced by Dedupe::CLI::Cli::Run().

{
  //we search for duplicates in the database, decide duplicates by filesize
  return FindDuplicates( Database.GetFiles(),
              [](Dedupe::FileInfo lhs, Dedupe::FileInfo rhs )
              { return lhs.GetSize() > rhs.GetSize();},

              [](Dedupe::FileInfo lhs, Dedupe::FileInfo rhs )
              { return lhs.GetSize() == rhs.GetSize();});
}

Dedupe::Core::Duplicates Dedupe::Core::Kernel::FindFilesizeDuplicatesExtern ( Dedupe::FilePaths  Paths,
bool  recursiv 
)

FindFilesizeDuplicatesExtern searches for duplicates in the given paths by the filesize. Give the start paths and recursive flag.

Returns:
a Duplicates Vector. If the vector is empty no duplicates are found

Definition at line 199 of file kernel.cpp.

References Dedupe::FileInfo::GetSize().

Referenced by Dedupe::CLI::Cli::Run().

{
  //we search for duplicates in the given orders, decide duplicates by filesize
  return FindExternDuplicates( Paths, recursiv,
              [](Dedupe::FileInfo lhs, Dedupe::FileInfo rhs )
              { return lhs.GetSize() > rhs.GetSize();},

              [](Dedupe::FileInfo lhs, Dedupe::FileInfo rhs )
              { return lhs.GetSize() == rhs.GetSize();});
}

Dedupe::Core::Duplicates Dedupe::Core::Kernel::FindHashDuplicates (  ) 

FindHashDuplicates searches for duplicates in the database by hashvalue

Returns:
a Duplicates Vector. If the vector is empty no duplicates are found

Definition at line 128 of file kernel.cpp.

References Dedupe::Dataholding::Dataholding::GetFiles(), and Dedupe::FileInfo::GetHash().

Referenced by Dedupe::CLI::Cli::Run().

{
  //we search for duplicate in the database, decide by hash
  return FindDuplicates( Database.GetFiles(),
                        [](Dedupe::FileInfo lhs, Dedupe::FileInfo rhs )
                            { return lhs.GetHash() > rhs.GetHash(); },
                         [](Dedupe::FileInfo lhs, Dedupe::FileInfo rhs )
                            { return lhs.GetHash() == rhs.GetHash(); });
}

Dedupe::Core::Duplicates Dedupe::Core::Kernel::FindHashDuplicatesExtern ( Dedupe::FilePaths  Paths,
bool  recursiv 
)

FindHashDuplicatesExtern searches for duplicates in the given paths by the hash. Give the start paths and recursive flag.

Returns:
a Duplicates Vector. If the vector is empty no duplicates are found

Definition at line 138 of file kernel.cpp.

References Dedupe::FileInfo::GetHash(), and Dedupe::Hash::Hash< T >::HashFileInfo().

Referenced by Dedupe::CLI::Cli::Run().

{
  Dedupe::FileStream AllFilesFromUser;

  AllFilesFromUser = FileAndDirectoryHandler( Paths, recursiv );

  std::function<void(Dedupe::FileInfo &Info)>HashFunc =
  std::bind( &Dedupe::Hash::Hash64::HashFileInfo, &Hasher, std::placeholders::_1 );

  Threadcontroller( HashFunc, AllFilesFromUser );

  //we search for duplicate in the given orders, decide by hash
  return FindDuplicates( AllFilesFromUser,
                        [](Dedupe::FileInfo lhs, Dedupe::FileInfo rhs )
                            { return lhs.GetHash() > rhs.GetHash(); },
                         [](Dedupe::FileInfo lhs, Dedupe::FileInfo rhs )
                            { return lhs.GetHash() == rhs.GetHash(); });
}

Dedupe::FileStream Dedupe::Core::Kernel::GetDatabase (  ) 

GetDatabase returns a FileStream with all files that are stored in the database

Definition at line 61 of file kernel.cpp.

References Dedupe::Dataholding::Dataholding::GetFiles().

{
  return Database.GetFiles();
}

void Dedupe::Core::Kernel::ListDatabase (  ) 

ListDatabase writes all Files that are stored in the database to the message stream

Definition at line 44 of file kernel.cpp.

References Dedupe::Dataholding::Dataholding::GetFiles().

Referenced by Dedupe::CLI::Cli::Run().

{
  Dedupe::FileStream Files( Database.GetFiles());
  for( Dedupe::FileStream::const_iterator it = Files.begin();
                                          it != Files.end();
                                          ++it )
  {
    MessageOut << "LIST:"
               << it->GetPath() << ":"
               << it->GetSize() << ":"
               << it->GetDateChanged() << ":"
               << it->GetType() << ":"
               << it->GetHash() << "\n";
  }

}

void Dedupe::Core::Kernel::ProcessDuplicates ( FilesToProcess  Dups  ) 

After Duplicates are decided by the user, give the Duplicates back to the kernel, which will be process like the user decided.

Definition at line 313 of file kernel.cpp.

{
  /*boost::system::error_code ec;

  for( auto it = Dups.begin(); it != Dups.end(); ++it )
  {
    for( auto InIt= it->begin(); InIt != it->end(); ++InIt )
    {
      switch( InIt->second() )
      {
        case Dedupe::Core::HandleDuplicates::Empty : continue; break;

        case Dedupe::Core::HandleDuplicates::Keep  : continue; break;

        case Dedupe::Core::HandleDuplicates::MarkAsKeep :

        InIt->first.SetKeep( true );
        Database.UpdateFile( InIt->first);
        break;

        case Dedupe::Core::HandleDuplicates::Delete:

        MessageOut << "Deleting file: " << InIt->first.GetPath() << std::endl;
        Database.DelFile( InIt->first );
        boost::filesystem::remove( InIt->first.GetPath(),ec);
        if( ec != 0 ) MessageOut << ec.message();
        break;

        default : MessageOut << "Request can't be handled: Unknown Token\n";
      }
    }
  }*/
}

void Dedupe::Core::Kernel::QuitKernel ( bool &  AmIDead  ) 

The kernel runs in it's own thread, so call this function when the program should end. The kernel finishs it's work stores true in the given bool variable and then kill himself. THIS FUNCTION IS INCOMPLETE YET

void Dedupe::Core::Kernel::TrackFiles ( Dedupe::FilePaths const &  Paths,
bool  recursiv 
)

TrackFiles appends the given file(s) or directory(ies) to the processed files from dedupe. Those files will be used to find duplicates

Definition at line 22 of file kernel.cpp.

Referenced by Dedupe::CLI::Cli::Run().

{
  boost::function<void ( Dedupe::FileInfo& )>AddFunction;

  AddFunction = boost::bind( &Dedupe::Core::Kernel::AddFile, this, _1 );

  FileAndDirectoryHandlerToFunction( Paths, recursiv, AddFunction );
}

void Dedupe::Core::Kernel::UntrackFiles ( Dedupe::FilePaths const &  Paths,
bool  recursiv 
)

UntrackFiles deletes the given file(s) or dirtory(ies) from the processed files of dedupe.

Definition at line 66 of file kernel.cpp.

References Dedupe::Dataholding::Dataholding::DelFile().

Referenced by Dedupe::CLI::Cli::Run().

{
  boost::function<void ( Dedupe::FileInfo& )>DelFunction;

  DelFunction = boost::bind( &Dedupe::Dataholding::Dataholding::DelFile, &Database, _1 );

  FileAndDirectoryHandlerToFunction( Paths, recursiv, DelFunction );
}


The documentation for this class was generated from the following files: