1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-08-22 16:00:50 +00:00

Move scan's core code into new machinery lib.

This commit is contained in:
King_DuckZ 2016-01-05 12:35:46 +00:00
parent 487b8efe61
commit 4e29200b47
26 changed files with 53 additions and 32 deletions

View file

@ -0,0 +1,62 @@
/* Copyright 2015, Michele Santullo
* This file is part of "dindexer".
*
* "dindexer" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "dindexer" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef idB6D385B7779240308449D6081CB790F1
#define idB6D385B7779240308449D6081CB790F1
#include "filestats.hpp"
#include <vector>
#include <functional>
#include <boost/utility/string_ref.hpp>
namespace fastf {
struct StringWithLength {
StringWithLength ( const char* parStr, int parLen ) :
str(parStr),
len(parLen)
{
}
const char* const str;
const int len;
};
class FileSearcher {
public:
typedef std::vector<StringWithLength> ConstCharVecType;
typedef std::function<bool(const char*, const FileStats&)> CallbackType;
explicit FileSearcher ( boost::string_ref parBaseDir );
~FileSearcher ( void ) noexcept;
void Search ( const ConstCharVecType& parExtensions, const ConstCharVecType& parIgnorePaths );
void SetFollowSymlinks ( bool parFollow ) noexcept { followSymlinks_ = parFollow; }
bool FollowSymlinks ( void ) const noexcept { return followSymlinks_; }
void SetRemainInFilesystem ( bool parRemain ) noexcept { remainInFilesystem_ = parRemain; }
bool RemainInFilesystem ( void ) const noexcept { return remainInFilesystem_; }
void SetCallback ( CallbackType parCallback );
private:
CallbackType callback_;
const std::string baseDir_;
bool followSymlinks_;
bool remainInFilesystem_;
};
} //namespace fastf
#endif

View file

@ -0,0 +1,33 @@
/* Copyright 2015, Michele Santullo
* This file is part of "dindexer".
*
* "dindexer" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "dindexer" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef id4A7D7AB671954418939FC0BDA19C5B3F
#define id4A7D7AB671954418939FC0BDA19C5B3F
#include <ctime>
namespace fastf {
struct FileStats {
int level;
std::time_t atime;
std::time_t mtime;
bool is_dir;
bool is_symlink;
};
} //namespace fastf
#endif

View file

@ -0,0 +1,77 @@
/* Copyright 2015, Michele Santullo
* This file is part of "dindexer".
*
* "dindexer" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "dindexer" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef idE555EF56730442C1ADDC7B2AE7A9340E
#define idE555EF56730442C1ADDC7B2AE7A9340E
#include <memory>
#include <string>
#include <vector>
#if !defined(NDEBUG)
# define INDEXER_VERBOSE
#endif
#if defined(WITH_PROGRESS_FEEDBACK)
namespace std {
class condition_variable;
} //namespace std
#endif
namespace fastf {
struct FileStats;
} //namespace fastf
namespace dinlib {
struct Settings;
} //namespace dinlib
namespace din {
struct FileRecordData;
class Indexer {
public:
Indexer ( void );
Indexer ( Indexer&& ) = default;
Indexer ( const Indexer& ) = delete;
~Indexer ( void ) noexcept;
bool add_path ( const char* parPath, const fastf::FileStats& parStats );
#if defined(INDEXER_VERBOSE)
void dump ( void ) const;
#endif
std::size_t total_items ( void ) const;
std::string operator[] ( std::size_t parIndex ) const;
#if defined(WITH_PROGRESS_FEEDBACK)
std::size_t processed_items ( void ) const;
std::string current_item ( void ) const;
std::condition_variable& step_notify ( void );
#endif
void calculate_hash ( void );
bool empty ( void ) const;
void ignore_read_errors ( bool parIgnore );
const std::vector<FileRecordData>& record_data ( void ) const;
private:
struct LocalData;
std::unique_ptr<LocalData> m_local_data;
};
} //namespace din
#endif

View file

@ -0,0 +1,43 @@
/* Copyright 2015, Michele Santullo
* This file is part of "dindexer".
*
* "dindexer" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "dindexer" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef id66D41389BC59433CA58E325395A6197B
#define id66D41389BC59433CA58E325395A6197B
#include <string>
#include <stdexcept>
#include "dindexer-common/mediatypes.hpp"
namespace din {
#if defined(WITH_MEDIA_AUTODETECT)
dinlib::MediaTypes guess_media_type ( std::string&& parPath );
class UnknownMediaTypeException : std::runtime_error {
public:
UnknownMediaTypeException ( const std::string& parWhat );
UnknownMediaTypeException ( const char* parWhat );
};
class CantAutodetectException : std::runtime_error {
public:
CantAutodetectException ( const std::string& parWhat );
CantAutodetectException ( const char* parWhat );
};
#endif
} //namespace din
#endif

View file

@ -0,0 +1,86 @@
/* Copyright 2015, Michele Santullo
* This file is part of "dindexer".
*
* "dindexer" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "dindexer" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef id3CD7F105AC314540A864487E981E5A7E
#define id3CD7F105AC314540A864487E981E5A7E
#include "tiger.hpp"
#include <string>
#include <boost/utility/string_ref.hpp>
#include <cstdint>
#include <ctime>
#include <boost/flyweight.hpp>
#include <boost/flyweight/no_locking.hpp>
namespace din {
struct FileRecordData {
struct MimeStringTagStruct { };
typedef boost::flyweights::tag<MimeStringTagStruct> MimeStringTag;
typedef boost::flyweight<std::string, boost::flyweights::no_locking, MimeStringTag> mime_string;
FileRecordData ( void ) = default;
FileRecordData ( const char* parPath, std::time_t parATime, std::time_t parMTime, uint64_t parLevel, bool parIsDir, bool parIsSymLink ) :
hash {},
path(parPath),
mime_full(),
atime(parATime),
mtime(parMTime),
mime_type(),
mime_charset(),
size(0),
level(parLevel),
is_directory(parIsDir),
is_symlink(parIsSymLink),
unreadable(false),
hash_valid(false)
{
}
FileRecordData ( const FileRecordData& ) = delete;
FileRecordData ( FileRecordData&& ) = default;
FileRecordData& operator= ( const FileRecordData& ) = delete;
FileRecordData& operator= ( FileRecordData&& ) = default;
bool operator== ( const FileRecordData& ) const = delete;
TigerHash hash;
std::string path;
mime_string mime_full;
std::time_t atime;
std::time_t mtime;
boost::string_ref mime_type;
boost::string_ref mime_charset;
uint64_t size;
uint16_t level;
bool is_directory;
bool is_symlink;
bool unreadable;
bool hash_valid;
};
struct SetRecordDataFull {
std::string name;
uint32_t disk_number;
char type;
};
struct SetRecordData {
const boost::string_ref name;
const char type;
};
} //namespace din
#endif

View file

@ -0,0 +1,49 @@
/* Copyright 2015, Michele Santullo
* This file is part of "dindexer".
*
* "dindexer" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "dindexer" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef idBE93AF97FA4343ECA2BC8FB1FD3E5E60
#define idBE93AF97FA4343ECA2BC8FB1FD3E5E60
#include <cstdint>
#include <string>
#include <vector>
namespace din {
struct TigerHash {
TigerHash ( void ) = default;
union {
struct {
uint64_t part_a;
uint64_t part_b;
uint64_t part_c;
};
uint64_t data[3];
uint8_t byte_data[sizeof(uint64_t) * 3];
};
};
static_assert(sizeof(TigerHash) == 24, "Wrong struct size");
void tiger_file ( const std::string& parPath, TigerHash& parHashFile, TigerHash& parHashDir, uint64_t& parSizeOut );
void tiger_init_hash ( TigerHash& parHash );
std::string tiger_to_string ( const TigerHash& parHash, bool parUpcase=false );
void tiger_data ( const std::string& parData, TigerHash& parHash );
void tiger_data ( const std::vector<char>& parData, TigerHash& parHash );
} //namespace din
#endif