Public Types | Public Member Functions | Friends

Dedupe::FileInfo Class Reference

#include <fileinfo.h>

Public Types

enum  FileStatus { FileStatusNotSet, FileOK, IgnoreFile, UncheckedFile }
enum  FileType {
  TFile, TDirectory, TSymbolicLink, TNotDefined,
  TNotAvailable
}

Public Member Functions

 FileInfo (Dedupe::FilePath PathToFile)
 FileInfo (Dedupe::FilePath PathToFile, unsigned long long size, time_t ChangeDate, Dedupe::FileInfo::FileType Type, bool keep)
 FileInfo (Dedupe::FilePath PathToFile, unsigned long long size, time_t ChangeDate, Dedupe::FileInfo::FileType Type, bool keep, unsigned long long HashValue)
Dedupe::FilePath GetPath () const
unsigned long long GetSize () const
time_t GetDateChanged () const
bool GetExisting () const
Dedupe::FileInfo::FileType GetType () const
void SetHash (unsigned long long const &value)
unsigned long long GetHash () const
void SetStatus (FileStatus value)
FileStatus GetStatus () const
void SetErrorMessage (std::string const &message)
std::string GetErrorMessage () const
bool GetKeep () const
void SetKeep (bool YesNo)
bool operator< (const FileInfo &rhs) const

Friends

bool operator== (const Dedupe::FileInfo rhs, const Dedupe::FileInfo lhs)
bool operator!= (const Dedupe::FileInfo rhs, const Dedupe::FileInfo lhs)
std::ostream & operator<< (std::ostream &os, const Dedupe::FileInfo &Info)
bool EqualNoHash (const Dedupe::FileInfo rhs, const Dedupe::FileInfo lhs)

Detailed Description

This class represents a single file on the harddisk with all needed informations about the file.

Definition at line 32 of file fileinfo.h.


Member Enumeration Documentation

FileStatus says, if the file is trustable

Enumerator:
FileStatusNotSet 

FileStatus is not set yet.

FileOK 

File is OK, all infos are here.

IgnoreFile 

File has Error, invalid data.

UncheckedFile 

File Data is unchecked, don't trust!

Definition at line 39 of file fileinfo.h.

    {
      FileStatusNotSet,  
      FileOK,                    
      IgnoreFile,               
      UncheckedFile       
    };

FileType defines different filetypes which are detected and used in Dedupe

Enumerator:
TFile 

Represents a File.

TDirectory 

Represents a Directory.

TSymbolicLink 

Represents a Symbolic Link.

TNotDefined 

Represents a Unknown Filetyp.

TNotAvailable 

Represents a not existing or not readable file.

Definition at line 51 of file fileinfo.h.

    {
      TFile,                
      TDirectory,       
      TSymbolicLink,
      TNotDefined,   
      TNotAvailable 
     };


Constructor & Destructor Documentation

Dedupe::FileInfo::FileInfo ( Dedupe::FilePath  PathToFile  ) 

Use the filepath to construct this class constructor with Dedupe::FilePath (typedef of boost::filesystem::path)

Definition at line 10 of file fileinfo.cpp.

References SetErrorMessage().

                                                   :
Path(""), Size( 0 ), DateChanged( 0 ), Existing( false ),
Type( TNotAvailable ), Hash( 0 ), Keep( false ),
StateOfFile( FileStatusNotSet ), FileSearchErrorMessage( "" )
{
  //Creates a portable path from a native path
  PathToFile.string();

  //Make path absolute and set it after creation of the portable path format
  Path = boost::filesystem::absolute(
                           PathToFile, boost::filesystem::current_path());

  /*create a boost error_code for use in the following boost functions;
    We don't want Exceptions*/
  boost::system::error_code ec;

  if( boost::filesystem::exists( Path, ec ) )
  {
    if( ec != 0 )
    {
      StateOfFile = IgnoreFile;
      SetErrorMessage( ec.message() );
    }
    Existing = true;

    // Get the filestatus
    boost::filesystem::file_status FileStatus;

    FileStatus  = boost::filesystem::symlink_status( Path, ec );
    if( ec != 0 )
    {
      StateOfFile = IgnoreFile;
      SetErrorMessage( ec.message() );
    }

    if( boost::filesystem::is_regular_file( FileStatus ) )
    {

      Size        = boost::filesystem::file_size( Path );

      DateChanged = boost::filesystem::last_write_time( Path );
      Type = TFile;
    }

    if( boost::filesystem::is_symlink( FileStatus ) )
    {
      Type = TSymbolicLink;
    }

    if( boost::filesystem::is_other( FileStatus ) )
    {
      Type = TNotDefined;
    }

    if( boost::filesystem::is_directory( FileStatus ) )
    {
      Type = TDirectory;
      DateChanged = boost::filesystem::last_write_time( Path );
    }
    StateOfFile = FileOK;
  }
  else StateOfFile = IgnoreFile;
}


Member Function Documentation

time_t Dedupe::FileInfo::GetDateChanged (  )  const
std::string Dedupe::FileInfo::GetErrorMessage (  )  const

Get the error message, that is stored, if FileStatus is set to IgnoreFile

Definition at line 166 of file fileinfo.cpp.

{
  return FileSearchErrorMessage;
}

bool Dedupe::FileInfo::GetExisting (  )  const
Returns:
true, if file is existing

Definition at line 119 of file fileinfo.cpp.

{
  return Existing;
}

unsigned long long Dedupe::FileInfo::GetHash (  )  const
bool Dedupe::FileInfo::GetKeep (  )  const [inline]
Returns:
true, if the keep flag is set

Definition at line 146 of file fileinfo.h.

Referenced by Dedupe::Dataholding::Dataholding::AddFile(), and Dedupe::Dataholding::Dataholding::UpdateFile().

{ return Keep; }

Dedupe::FilePath Dedupe::FileInfo::GetPath (  )  const
unsigned long long Dedupe::FileInfo::GetSize (  )  const
Dedupe::FileInfo::FileStatus Dedupe::FileInfo::GetStatus (  )  const

Get FileStatus

Returns:
one constant from FileStatus

Definition at line 154 of file fileinfo.cpp.

Referenced by Dedupe::FileSearch::SearchFiles::Search(), and Dedupe::FileSearch::SearchFiles::SearchRecursive().

{
  return StateOfFile;
}

Dedupe::FileInfo::FileType Dedupe::FileInfo::GetType (  )  const
Returns:
one constant from FileType

Definition at line 126 of file fileinfo.cpp.

Referenced by Dedupe::Dataholding::Dataholding::AddFile(), Dedupe::FileSearch::SearchFiles::Search(), and Dedupe::Dataholding::Dataholding::UpdateFile().

{
  return Type;
}

bool Dedupe::FileInfo::operator< ( const FileInfo rhs  )  const [inline]

The operator is here to make std::sort() usable with FileInfo

Definition at line 156 of file fileinfo.h.

{ return Path < rhs.Path; }

void Dedupe::FileInfo::SetErrorMessage ( std::string const &  message  ) 

FileSearch and the FileInfo constructor can store some error messages here. Error Messages are only stored, if GetStatus has value "IgnoreFile"

Definition at line 160 of file fileinfo.cpp.

Referenced by FileInfo().

{
  FileSearchErrorMessage = message;
}

void Dedupe::FileInfo::SetHash ( unsigned long long const &  value  ) 

Sets the Hashvalue

Definition at line 133 of file fileinfo.cpp.

Referenced by Dedupe::Hash::Hash< T >::HashFileInfo().

{
  Hash = value;
}

void Dedupe::FileInfo::SetKeep ( bool  YesNo  )  [inline]

Give a bool to set the keep option. Keep is false by default

Definition at line 151 of file fileinfo.h.

{ Keep = YesNo; }

void Dedupe::FileInfo::SetStatus ( FileStatus  value  ) 

Set FileStatus

Definition at line 147 of file fileinfo.cpp.

{
  StateOfFile = value;
}


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