mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-08-14 14:49:48 +00:00
Move scan's core code into new machinery lib.
This commit is contained in:
parent
487b8efe61
commit
4e29200b47
26 changed files with 53 additions and 32 deletions
38
src/machinery/CMakeLists.txt
Normal file
38
src/machinery/CMakeLists.txt
Normal file
|
@ -0,0 +1,38 @@
|
|||
project(${bare_name}-machinery CXX C)
|
||||
|
||||
include(WithMediaAutodetect)
|
||||
find_package(Magic REQUIRED)
|
||||
|
||||
add_library(${PROJECT_NAME} SHARED
|
||||
indexer.cpp
|
||||
pathname.cpp
|
||||
tiger.c
|
||||
tiger.cpp
|
||||
mimetype.cpp
|
||||
filesearcher.cpp
|
||||
discinfo.cpp
|
||||
mediatype.cpp
|
||||
)
|
||||
|
||||
#target_include_directories(${PROJECT_NAME}
|
||||
#)
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE ${MAGIC_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE ${bare_name}-if
|
||||
PRIVATE ${MAGIC_LIBRARIES}
|
||||
)
|
||||
|
||||
if (DINDEXER_WITH_MEDIA_AUTODETECT)
|
||||
target_include_directories(${PROJECT_NAME} SYSTEM
|
||||
PRIVATE ${BLKID_INCLUDE_DIRS}
|
||||
)
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE ${BLKID_LIBRARIES}
|
||||
)
|
||||
target_compile_definitions(${PROJECT_NAME}
|
||||
PRIVATE WITH_MEDIA_AUTODETECT
|
||||
)
|
||||
endif()
|
|
@ -15,7 +15,7 @@
|
|||
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "filesearcher.hpp"
|
||||
#include "dindexer-machinery/filesearcher.hpp"
|
||||
|
||||
#if !defined(_XOPEN_SOURCE)
|
||||
#define _XOPEN_SOURCE 500
|
|
@ -15,13 +15,13 @@
|
|||
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "indexer.hpp"
|
||||
#include "dindexer-machinery/indexer.hpp"
|
||||
#include "pathname.hpp"
|
||||
#include "tiger.hpp"
|
||||
#include "dindexer-machinery/tiger.hpp"
|
||||
#include "dindexer-common/settings.hpp"
|
||||
#include "filestats.hpp"
|
||||
#include "dindexer-machinery/filestats.hpp"
|
||||
#include "mimetype.hpp"
|
||||
#include "recorddata.hpp"
|
||||
#include "dindexer-machinery/recorddata.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <stdexcept>
|
|
@ -15,7 +15,7 @@
|
|||
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "mediatype.hpp"
|
||||
#include "dindexer-machinery/mediatype.hpp"
|
||||
#include "pathname.hpp"
|
||||
#include "discinfo.hpp"
|
||||
#include <utility>
|
|
@ -15,7 +15,7 @@
|
|||
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "tiger.hpp"
|
||||
#include "dindexer-machinery/tiger.hpp"
|
||||
#include <fstream>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
|
@ -1,33 +1,21 @@
|
|||
project(${bare_name}-scan CXX C)
|
||||
project(${bare_name}-scan CXX)
|
||||
|
||||
include(WithMediaAutodetect)
|
||||
find_package(Magic REQUIRED)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
main.cpp
|
||||
filesearcher.cpp
|
||||
pathname.cpp
|
||||
indexer.cpp
|
||||
tiger.c
|
||||
tiger.cpp
|
||||
dbbackend.cpp
|
||||
commandline.cpp
|
||||
discinfo.cpp
|
||||
mediatype.cpp
|
||||
mimetype.cpp
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..
|
||||
)
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE ${MAGIC_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE ${bare_name}-if
|
||||
PRIVATE ${bare_name}-common
|
||||
PRIVATE ${MAGIC_LIBRARIES}
|
||||
PRIVATE ${bare_name}-machinery
|
||||
)
|
||||
|
||||
string(REPLACE "${bare_name}-" "" ACTION_NAME "${PROJECT_NAME}")
|
||||
|
@ -36,12 +24,6 @@ target_compile_definitions(${PROJECT_NAME}
|
|||
)
|
||||
|
||||
if (DINDEXER_WITH_MEDIA_AUTODETECT)
|
||||
target_include_directories(${PROJECT_NAME} SYSTEM
|
||||
PRIVATE ${BLKID_INCLUDE_DIRS}
|
||||
)
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE ${BLKID_LIBRARIES}
|
||||
)
|
||||
target_compile_definitions(${PROJECT_NAME}
|
||||
PRIVATE WITH_MEDIA_AUTODETECT
|
||||
)
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#define id1B7A42F6E46547A6AB0F914E2A91399F
|
||||
|
||||
#include <boost/program_options/variables_map.hpp>
|
||||
#include "mediatype.hpp"
|
||||
#include "dindexer-machinery/mediatype.hpp"
|
||||
|
||||
namespace din {
|
||||
bool parse_commandline ( int parArgc, char* parArgv[], boost::program_options::variables_map& parVarMap );
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "dbbackend.hpp"
|
||||
#include "pq/connection.hpp"
|
||||
#include "dindexer-common/settings.hpp"
|
||||
#include "recorddata.hpp"
|
||||
#include "dindexer-machinery/recorddata.hpp"
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
/* 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
|
|
@ -1,33 +0,0 @@
|
|||
/* 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
|
|
@ -1,77 +0,0 @@
|
|||
/* 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
|
|
@ -19,10 +19,10 @@
|
|||
# undef WITH_PROGRESS_FEEDBACK
|
||||
#endif
|
||||
|
||||
#include "recorddata.hpp"
|
||||
#include "dindexer-machinery/recorddata.hpp"
|
||||
#include "dindexerConfig.h"
|
||||
#include "filesearcher.hpp"
|
||||
#include "indexer.hpp"
|
||||
#include "dindexer-machinery/filesearcher.hpp"
|
||||
#include "dindexer-machinery/indexer.hpp"
|
||||
#include "dindexer-common/settings.hpp"
|
||||
#include "commandline.hpp"
|
||||
#include "dbbackend.hpp"
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
/* 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
|
|
@ -1,86 +0,0 @@
|
|||
/* 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
|
|
@ -1,49 +0,0 @@
|
|||
/* 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
|
Loading…
Add table
Add a link
Reference in a new issue