mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2024-11-29 01:33:46 +00:00
Move db dbsource files to the postgresql backend lib and rename namespace.
This commit is contained in:
parent
baa67138eb
commit
70caa9e26c
24 changed files with 166 additions and 131 deletions
|
@ -19,7 +19,7 @@
|
|||
#define id63F35BA8B3C94A129291D963ABE66018
|
||||
|
||||
#include "dindexer-machinery/recorddata.hpp"
|
||||
#include "flatinsertin2dlist.hpp"
|
||||
#include "helpers/flatinsertin2dlist.hpp"
|
||||
#include "helpers/MaxSizedArray.hpp"
|
||||
#include <memory>
|
||||
#include <cstdint>
|
||||
|
@ -31,17 +31,15 @@
|
|||
#include <functional>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
|
||||
namespace dinlib {
|
||||
struct SettingsDB;
|
||||
} //namespace dinlib
|
||||
|
||||
namespace pq {
|
||||
class Connection;
|
||||
} //namespace pq
|
||||
|
||||
namespace din {
|
||||
namespace dinbpostgres {
|
||||
using dinhelp::MaxSizedArray;
|
||||
|
||||
struct Settings;
|
||||
|
||||
enum SetDetails {
|
||||
SetDetail_Desc = 0x01,
|
||||
SetDetail_Type = 0x02,
|
||||
|
@ -69,7 +67,7 @@ namespace din {
|
|||
|
||||
class DBSource {
|
||||
public:
|
||||
explicit DBSource ( const dinlib::SettingsDB& parDBSettings );
|
||||
explicit DBSource ( const Settings& parDBSettings );
|
||||
~DBSource ( void ) noexcept;
|
||||
|
||||
void disconnect ( void );
|
||||
|
@ -121,8 +119,9 @@ namespace din {
|
|||
|
||||
template <SetDetails... D>
|
||||
auto DBSource::set_details (const std::vector<uint32_t>& parIDs) -> std::vector<MaxSizedArray<std::string, sizeof...(D)>> {
|
||||
using dinhelp::FlatInsertIn2DList;
|
||||
typedef std::vector<MaxSizedArray<std::string, sizeof...(D)>> ReturnType;
|
||||
typedef void(din::FlatInsertIn2DList<ReturnType>::*FlatPushBackFunc)(std::string&&);
|
||||
typedef void(FlatInsertIn2DList<ReturnType>::*FlatPushBackFunc)(std::string&&);
|
||||
|
||||
const auto columns = implem::make_columns_vec<SetDetails, D...>(m_set_details_map);
|
||||
|
||||
|
@ -135,8 +134,9 @@ namespace din {
|
|||
|
||||
template <FileDetails... D>
|
||||
auto DBSource::file_details (uint32_t parSetID, uint16_t parLevel, boost::string_ref parDir) -> std::vector<MaxSizedArray<std::string, sizeof...(D)>> {
|
||||
using dinhelp::FlatInsertIn2DList;
|
||||
typedef std::vector<MaxSizedArray<std::string, sizeof...(D)>> ReturnType;
|
||||
typedef void(din::FlatInsertIn2DList<ReturnType>::*FlatPushBackFunc)(std::string&&);
|
||||
typedef void(FlatInsertIn2DList<ReturnType>::*FlatPushBackFunc)(std::string&&);
|
||||
|
||||
const auto columns = implem::make_columns_vec<FileDetails, D...>(m_file_details_map);
|
||||
|
||||
|
@ -146,6 +146,6 @@ namespace din {
|
|||
this->query_files_in_dir(columns, parDir, parLevel, parSetID, std::bind(pback_func, &flat_list, std::placeholders::_1));
|
||||
return list;
|
||||
}
|
||||
} //namespace din
|
||||
} //namespace dinbpostgres
|
||||
|
||||
#endif
|
|
@ -24,15 +24,13 @@
|
|||
#include <cstdint>
|
||||
#include <map>
|
||||
|
||||
namespace dinlib {
|
||||
struct SettingsDB;
|
||||
} //namespace dinlib
|
||||
namespace dinbpostgres {
|
||||
struct Settings;
|
||||
|
||||
namespace din {
|
||||
using IDDescMap = std::map<uint32_t, std::string>;
|
||||
using ConfirmDeleCallback = std::function<bool(const IDDescMap&)>;
|
||||
|
||||
void delete_group_from_db ( const dinlib::SettingsDB& parDB, const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf );
|
||||
} //namespace din
|
||||
void delete_group_from_db ( const Settings& parDB, const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf );
|
||||
} //namespace dinbpostgres
|
||||
|
||||
#endif
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#ifndef id1AE05A59AE0E4A4490040FD85D9AF665
|
||||
#define id1AE05A59AE0E4A4490040FD85D9AF665
|
||||
|
||||
#include "dindexer-common/settings.hpp"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
@ -28,7 +27,9 @@ namespace mchlib {
|
|||
struct TigerHash;
|
||||
} //namespace mchlib
|
||||
|
||||
namespace din {
|
||||
namespace dinbpostgres {
|
||||
struct Settings;
|
||||
|
||||
struct LocatedItem {
|
||||
std::string path;
|
||||
uint64_t id;
|
||||
|
@ -44,10 +45,10 @@ namespace din {
|
|||
|
||||
using TagList = std::vector<boost::string_ref>;
|
||||
|
||||
std::vector<LocatedItem> locate_in_db ( const dinlib::SettingsDB& parDB, const std::string& parSearch, const TagList& parTags );
|
||||
std::vector<LocatedItem> locate_in_db ( const dinlib::SettingsDB& parDB, const mchlib::TigerHash& parSearch, const TagList& parTags );
|
||||
std::vector<LocatedSet> locate_sets_in_db ( const dinlib::SettingsDB& parDB, const std::string& parSearch, bool parCaseInsensitive );
|
||||
std::vector<LocatedSet> locate_sets_in_db ( const dinlib::SettingsDB& parDB, const std::string& parSearch, const std::vector<uint32_t>& parSets, bool parCaseInsensitive );
|
||||
} //namespace din
|
||||
std::vector<LocatedItem> locate_in_db ( const Settings& parDB, const std::string& parSearch, const TagList& parTags );
|
||||
std::vector<LocatedItem> locate_in_db ( const Settings& parDB, const mchlib::TigerHash& parSearch, const TagList& parTags );
|
||||
std::vector<LocatedSet> locate_sets_in_db ( const Settings& parDB, const std::string& parSearch, bool parCaseInsensitive );
|
||||
std::vector<LocatedSet> locate_sets_in_db ( const Settings& parDB, const std::string& parSearch, const std::vector<uint32_t>& parSets, bool parCaseInsensitive );
|
||||
} //namespace dinbpostgres
|
||||
|
||||
#endif
|
||||
|
|
|
@ -22,10 +22,6 @@
|
|||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
namespace dinlib {
|
||||
struct SettingsDB;;
|
||||
} //namespace dinlib
|
||||
|
||||
namespace mchlib {
|
||||
struct FileRecordData;
|
||||
struct SetRecordData;
|
||||
|
@ -33,9 +29,11 @@ namespace mchlib {
|
|||
struct TigerHash;
|
||||
} //namespace mchlib
|
||||
|
||||
namespace din {
|
||||
void write_to_db ( const dinlib::SettingsDB& parDB, const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordData& parSetData, const std::string& parSignature );
|
||||
bool read_from_db ( mchlib::FileRecordData& parItem, mchlib::SetRecordDataFull& parSet, const dinlib::SettingsDB& parDB, const mchlib::TigerHash& parHash );
|
||||
} //namespace din
|
||||
namespace dinbpostgres {
|
||||
struct Settings;;
|
||||
|
||||
void write_to_db ( const Settings& parDB, const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordData& parSetData, const std::string& parSignature );
|
||||
bool read_from_db ( mchlib::FileRecordData& parItem, mchlib::SetRecordDataFull& parSet, const Settings& parDB, const mchlib::TigerHash& parHash );
|
||||
} //namespace dinbpostgres
|
||||
|
||||
#endif
|
||||
|
|
34
include/backends/postgresql/settings.hpp
Normal file
34
include/backends/postgresql/settings.hpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
/* Copyright 2015, 2016, 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 idC895D12FEB324387A37FF631E0C09560
|
||||
#define idC895D12FEB324387A37FF631E0C09560
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
namespace dinbpostgres {
|
||||
struct Settings {
|
||||
std::string address;
|
||||
std::string username;
|
||||
std::string password;
|
||||
std::string dbname;
|
||||
uint16_t port;
|
||||
};
|
||||
} //namespace dinbpostgres
|
||||
|
||||
#endif
|
|
@ -22,23 +22,21 @@
|
|||
#include <boost/utility/string_ref.hpp>
|
||||
#include <cstdint>
|
||||
|
||||
namespace dinlib {
|
||||
struct SettingsDB;
|
||||
} //namespace dinlib
|
||||
namespace dinbpostgres {
|
||||
struct Settings;
|
||||
|
||||
namespace din {
|
||||
struct OwnerSetInfo {
|
||||
uint32_t group_id;
|
||||
bool is_valid;
|
||||
};
|
||||
|
||||
void tag_files ( const dinlib::SettingsDB& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
|
||||
void tag_files ( const dinlib::SettingsDB& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
|
||||
void tag_files ( const Settings& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
|
||||
void tag_files ( const Settings& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
|
||||
|
||||
void delete_tags ( const dinlib::SettingsDB& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
|
||||
void delete_tags ( const dinlib::SettingsDB& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
|
||||
void delete_all_tags ( const dinlib::SettingsDB& parDB, const std::vector<uint64_t>& parFiles, OwnerSetInfo parSet );
|
||||
void delete_all_tags ( const dinlib::SettingsDB& parDB, const std::vector<std::string>& parRegexes, OwnerSetInfo parSet );
|
||||
} //namespace din
|
||||
void delete_tags ( const Settings& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
|
||||
void delete_tags ( const Settings& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
|
||||
void delete_all_tags ( const Settings& parDB, const std::vector<uint64_t>& parFiles, OwnerSetInfo parSet );
|
||||
void delete_all_tags ( const Settings& parDB, const std::vector<std::string>& parRegexes, OwnerSetInfo parSet );
|
||||
} //namespace dinbpostgres
|
||||
|
||||
#endif
|
||||
|
|
|
@ -19,19 +19,11 @@
|
|||
#define idDC29E3C667BD4793BA0644AE7DC5BD3F
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include "backends/postgresql/settings.hpp"
|
||||
|
||||
namespace dinlib {
|
||||
struct SettingsDB {
|
||||
std::string address;
|
||||
std::string username;
|
||||
std::string password;
|
||||
std::string dbname;
|
||||
uint16_t port;
|
||||
};
|
||||
|
||||
struct Settings {
|
||||
SettingsDB db;
|
||||
dinbpostgres::Settings db;
|
||||
};
|
||||
|
||||
bool load_settings ( const std::string& parPath, Settings& parOut, bool parExpand=true );
|
||||
|
|
|
@ -18,13 +18,21 @@
|
|||
#ifndef idAA901DA47E234E37B325B3192EF50423
|
||||
#define idAA901DA47E234E37B325B3192EF50423
|
||||
|
||||
//Use this function to turn a 1D sequence of elements that are logically grouped
|
||||
//together by position into a 2D list. For example, if you have an input sequence
|
||||
//like {A1, B1, C1, A2, B2, C2, A3, B3, C3} and you want to turn it into
|
||||
//{ {A1, B1, C1}, {A2, B2, C2}, {A3, B3, C3} } you can use these functions to
|
||||
//achieve that. You need to specify the size of the innermost groups, 3 in the
|
||||
//example just given, and push_back() will automatically move to the next
|
||||
//sublist every 3 items.
|
||||
|
||||
#include <cstddef>
|
||||
#include <cassert>
|
||||
#include <ciso646>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
namespace din {
|
||||
namespace dinhelp {
|
||||
template <typename OuterList, typename InnerList=typename OuterList::value_type, typename InnerVal=typename InnerList::value_type>
|
||||
class FlatInsertIn2DList {
|
||||
public:
|
||||
|
@ -44,8 +52,8 @@ namespace din {
|
|||
const std::size_t m_inner_count;
|
||||
const std::size_t m_outer_count;
|
||||
};
|
||||
} //namespace din
|
||||
} //namespace dinhelp
|
||||
|
||||
#include "flatinsertin2dlist.inl"
|
||||
#include "implem/flatinsertin2dlist.inl"
|
||||
|
||||
#endif
|
|
@ -15,7 +15,7 @@
|
|||
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace din {
|
||||
namespace dinhelp {
|
||||
template <typename OuterList, typename InnerList, typename InnerVal>
|
||||
FlatInsertIn2DList<OuterList, InnerList, InnerVal>::FlatInsertIn2DList (list_type* parList, std::size_t parInnerCount, std::size_t parOuterCount) :
|
||||
m_list(parList),
|
||||
|
@ -70,4 +70,4 @@ namespace din {
|
|||
return (m_list->size() - 1) * m_inner_count + m_list[m_list->size() - 1].size();
|
||||
}
|
||||
}
|
||||
} //namespace din
|
||||
} //namespace dinhelp
|
|
@ -5,6 +5,7 @@ add_library(${PROJECT_NAME} STATIC
|
|||
delete.cpp
|
||||
locate.cpp
|
||||
scan.cpp
|
||||
dbsource.cpp
|
||||
)
|
||||
|
||||
#target_include_directories(${PROJECT_NAME}
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "dbsource.hpp"
|
||||
#include "dindexer-common/settings.hpp"
|
||||
#include "backends/postgresql/dbsource.hpp"
|
||||
#include "backends/postgresql/settings.hpp"
|
||||
#include "pq/connection.hpp"
|
||||
#include "helpers/infix_iterator.hpp"
|
||||
#include <ciso646>
|
||||
|
@ -25,7 +25,7 @@
|
|||
#include <sstream>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
|
||||
namespace din {
|
||||
namespace dinbpostgres {
|
||||
namespace {
|
||||
const uint32_t g_files_query_limit = 500;
|
||||
|
||||
|
@ -62,7 +62,7 @@ namespace din {
|
|||
};
|
||||
|
||||
struct DBSource::LocalData {
|
||||
explicit LocalData ( const dinlib::SettingsDB& parDBSettings ) :
|
||||
explicit LocalData ( const Settings& parDBSettings ) :
|
||||
conn(
|
||||
std::string(parDBSettings.username),
|
||||
std::string(parDBSettings.password),
|
||||
|
@ -76,7 +76,7 @@ namespace din {
|
|||
pq::Connection conn;
|
||||
};
|
||||
|
||||
DBSource::DBSource (const dinlib::SettingsDB& parDBSettings) :
|
||||
DBSource::DBSource (const Settings& parDBSettings) :
|
||||
m_local_data(new LocalData(parDBSettings))
|
||||
{
|
||||
assert(not m_local_data->conn.is_connected());
|
||||
|
@ -180,4 +180,4 @@ namespace din {
|
|||
}
|
||||
return retval;
|
||||
}
|
||||
} //namespace din
|
||||
} //namespace dinbpostgres
|
|
@ -16,8 +16,8 @@
|
|||
*/
|
||||
|
||||
#include "backends/postgresql/delete.hpp"
|
||||
#include "backends/postgresql/settings.hpp"
|
||||
#include "pq/connection.hpp"
|
||||
#include "dindexer-common/settings.hpp"
|
||||
#include "helpers/infix_iterator.hpp"
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
@ -27,7 +27,7 @@
|
|||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
namespace din {
|
||||
namespace dinbpostgres {
|
||||
namespace {
|
||||
IDDescMap fetch_existing_ids (pq::Connection& parConn, const std::vector<uint32_t>& parIDs) {
|
||||
using boost::lexical_cast;
|
||||
|
@ -50,7 +50,7 @@ namespace din {
|
|||
}
|
||||
} //unnamed namespace
|
||||
|
||||
void delete_group_from_db (const dinlib::SettingsDB& parDB, const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf) {
|
||||
void delete_group_from_db (const Settings& parDB, const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf) {
|
||||
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
|
||||
conn.connect();
|
||||
const auto dele_ids = fetch_existing_ids(conn, parIDs);
|
||||
|
@ -72,4 +72,4 @@ namespace din {
|
|||
|
||||
conn.query(oss.str());
|
||||
}
|
||||
} //namespace din
|
||||
} //namespace dinbpostgres
|
||||
|
|
|
@ -16,19 +16,20 @@
|
|||
*/
|
||||
|
||||
#include "backends/postgresql/locate.hpp"
|
||||
#include "backends/postgresql/settings.hpp"
|
||||
#include "pq/connection.hpp"
|
||||
#include "dindexer-machinery/tiger.hpp"
|
||||
#include <utility>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
namespace din {
|
||||
namespace dinbpostgres {
|
||||
namespace {
|
||||
const int g_max_results = 200;
|
||||
|
||||
pq::Connection make_pq_conn ( const dinlib::SettingsDB& parDB, bool parOpen=true );
|
||||
pq::Connection make_pq_conn ( const Settings& parDB, bool parOpen=true );
|
||||
|
||||
pq::Connection make_pq_conn (const dinlib::SettingsDB& parDB, bool parOpen) {
|
||||
pq::Connection make_pq_conn (const Settings& parDB, bool parOpen) {
|
||||
auto conn = pq::Connection(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
|
||||
if (parOpen) {
|
||||
conn.connect();
|
||||
|
@ -94,20 +95,20 @@ namespace din {
|
|||
}
|
||||
} //unnamed namespace
|
||||
|
||||
std::vector<LocatedItem> locate_in_db (const dinlib::SettingsDB& parDB, const std::string& parSearch, const TagList& parTags) {
|
||||
std::vector<LocatedItem> locate_in_db (const Settings& parDB, const std::string& parSearch, const TagList& parTags) {
|
||||
auto conn = make_pq_conn(parDB);
|
||||
|
||||
const char base_query[] = "SELECT \"path\",\"id\",\"group_id\" FROM \"files\" WHERE \"path\" ~ $1";
|
||||
return locate_in_db(conn, base_query, sizeof(base_query) - 1, "$2", parTags, parSearch);
|
||||
}
|
||||
|
||||
std::vector<LocatedItem> locate_in_db (const dinlib::SettingsDB& parDB, const mchlib::TigerHash& parSearch, const TagList& parTags) {
|
||||
std::vector<LocatedItem> locate_in_db (const Settings& parDB, const mchlib::TigerHash& parSearch, const TagList& parTags) {
|
||||
auto conn = make_pq_conn(parDB);
|
||||
const char base_query[] = "SELECT \"path\",\"id\",\"group_id\" FROM \"files\" WHERE \"hash\"=$1";
|
||||
return locate_in_db(conn, base_query, sizeof(base_query) - 1, "$2", parTags, mchlib::tiger_to_string(parSearch, true));
|
||||
}
|
||||
|
||||
std::vector<LocatedSet> locate_sets_in_db (const dinlib::SettingsDB& parDB, const std::string& parSearch, bool parCaseInsensitive) {
|
||||
std::vector<LocatedSet> locate_sets_in_db (const Settings& parDB, const std::string& parSearch, bool parCaseInsensitive) {
|
||||
auto conn = make_pq_conn(parDB);
|
||||
|
||||
const std::string query = std::string("SELECT \"id\", \"desc\", "
|
||||
|
@ -120,7 +121,7 @@ namespace din {
|
|||
return sets_result_to_vec(std::move(result));
|
||||
}
|
||||
|
||||
std::vector<LocatedSet> locate_sets_in_db (const dinlib::SettingsDB& parDB, const std::string& parSearch, const std::vector<uint32_t>& parSets, bool parCaseInsensitive) {
|
||||
std::vector<LocatedSet> locate_sets_in_db (const Settings& parDB, const std::string& parSearch, const std::vector<uint32_t>& parSets, bool parCaseInsensitive) {
|
||||
if (parSets.empty()) {
|
||||
return locate_sets_in_db(parDB, parSearch, parCaseInsensitive);
|
||||
}
|
||||
|
@ -136,4 +137,4 @@ namespace din {
|
|||
auto result = conn.query(query, parSearch, parCaseInsensitive, parSets);
|
||||
return sets_result_to_vec(std::move(result));
|
||||
}
|
||||
} //namespace din
|
||||
} //namespace dinbpostgres
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
*/
|
||||
|
||||
#include "backends/postgresql/scan.hpp"
|
||||
#include "backends/postgresql/settings.hpp"
|
||||
#include "pq/connection.hpp"
|
||||
#include "dindexer-common/settings.hpp"
|
||||
#include "dindexer-machinery/recorddata.hpp"
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
@ -28,11 +28,11 @@
|
|||
#include <boost/utility/string_ref.hpp>
|
||||
#include <chrono>
|
||||
|
||||
namespace din {
|
||||
namespace dinbpostgres {
|
||||
namespace {
|
||||
} //unnamed namespace
|
||||
|
||||
bool read_from_db (mchlib::FileRecordData& parItem, mchlib::SetRecordDataFull& parSet, const dinlib::SettingsDB& parDB, const mchlib::TigerHash& parHash) {
|
||||
bool read_from_db (mchlib::FileRecordData& parItem, mchlib::SetRecordDataFull& parSet, const Settings& parDB, const mchlib::TigerHash& parHash) {
|
||||
using boost::lexical_cast;
|
||||
|
||||
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
|
||||
|
@ -82,7 +82,7 @@ namespace din {
|
|||
return true;
|
||||
}
|
||||
|
||||
void write_to_db (const dinlib::SettingsDB& parDB, const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordData& parSetData, const std::string& parSignature) {
|
||||
void write_to_db (const Settings& parDB, const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordData& parSetData, const std::string& parSignature) {
|
||||
using std::chrono::system_clock;
|
||||
using boost::lexical_cast;
|
||||
|
||||
|
@ -144,4 +144,4 @@ namespace din {
|
|||
}
|
||||
conn.query("COMMIT;");
|
||||
}
|
||||
} //namespace din
|
||||
} //namespace dinbpostgres
|
||||
|
|
|
@ -16,12 +16,13 @@
|
|||
*/
|
||||
|
||||
#include "backends/postgresql/tag.hpp"
|
||||
#include "backends/postgresql/settings.hpp"
|
||||
#include "pq/connection.hpp"
|
||||
#include "dindexer-common/settings.hpp"
|
||||
#include <ciso646>
|
||||
|
||||
namespace din {
|
||||
void tag_files (const dinlib::SettingsDB& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet) {
|
||||
namespace dinbpostgres {
|
||||
void tag_files (const Settings& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet) {
|
||||
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
|
||||
conn.connect();
|
||||
|
||||
|
@ -37,7 +38,7 @@ namespace din {
|
|||
}
|
||||
}
|
||||
|
||||
void tag_files (const dinlib::SettingsDB& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet) {
|
||||
void tag_files (const Settings& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet) {
|
||||
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
|
||||
conn.connect();
|
||||
|
||||
|
@ -71,7 +72,7 @@ namespace din {
|
|||
}
|
||||
}
|
||||
|
||||
void delete_tags (const dinlib::SettingsDB& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet) {
|
||||
void delete_tags (const Settings& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet) {
|
||||
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
|
||||
conn.connect();
|
||||
|
||||
|
@ -97,7 +98,7 @@ namespace din {
|
|||
}
|
||||
}
|
||||
|
||||
void delete_tags (const dinlib::SettingsDB& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet) {
|
||||
void delete_tags (const Settings& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet) {
|
||||
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
|
||||
conn.connect();
|
||||
|
||||
|
@ -123,7 +124,7 @@ namespace din {
|
|||
}
|
||||
}
|
||||
|
||||
void delete_all_tags (const dinlib::SettingsDB& parDB, const std::vector<uint64_t>& parFiles, OwnerSetInfo parSet) {
|
||||
void delete_all_tags (const Settings& parDB, const std::vector<uint64_t>& parFiles, OwnerSetInfo parSet) {
|
||||
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
|
||||
conn.connect();
|
||||
|
||||
|
@ -139,7 +140,7 @@ namespace din {
|
|||
}
|
||||
}
|
||||
|
||||
void delete_all_tags (const dinlib::SettingsDB& parDB, const std::vector<std::string>& parRegexes, OwnerSetInfo parSet) {
|
||||
void delete_all_tags (const Settings& parDB, const std::vector<std::string>& parRegexes, OwnerSetInfo parSet) {
|
||||
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
|
||||
conn.connect();
|
||||
|
||||
|
@ -152,4 +153,4 @@ namespace din {
|
|||
conn.query(query, parRegexes);
|
||||
}
|
||||
}
|
||||
} //namespace din
|
||||
} //namespace dinbpostgres
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
|
||||
namespace YAML {
|
||||
template<>
|
||||
struct convert<dinlib::SettingsDB> {
|
||||
static Node encode (const dinlib::SettingsDB& parSettings) {
|
||||
struct convert<dinbpostgres::Settings> {
|
||||
static Node encode (const dinbpostgres::Settings& parSettings) {
|
||||
Node node;
|
||||
node["address"] = parSettings.address;
|
||||
node["username"] = parSettings.username;
|
||||
|
@ -33,7 +33,7 @@ namespace YAML {
|
|||
return node;
|
||||
}
|
||||
|
||||
static bool decode (const Node& parNode, dinlib::SettingsDB& parSettings) {
|
||||
static bool decode (const Node& parNode, dinbpostgres::Settings& parSettings) {
|
||||
if (not parNode.IsMap() or parNode.size() != 5) {
|
||||
return false;
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ namespace dinlib {
|
|||
auto settings = YAML::LoadFile(path);
|
||||
|
||||
if (settings["db_settings"]) {
|
||||
parOut.db = settings["db_settings"].as<dinlib::SettingsDB>();
|
||||
parOut.db = settings["db_settings"].as<dinbpostgres::Settings>();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include <cstdint>
|
||||
|
||||
namespace {
|
||||
bool confirm_delete (const din::IDDescMap& parMap) {
|
||||
bool confirm_delete (const dinbpostgres::IDDescMap& parMap) {
|
||||
for (const auto& itm : parMap) {
|
||||
std::cout << "ID " << itm.first << '\t' << itm.second << '\n';
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ namespace {
|
|||
return (answer.empty() or "y" == answer or "Y" == answer);
|
||||
}
|
||||
|
||||
bool always_delete (const din::IDDescMap&) {
|
||||
bool always_delete (const dinbpostgres::IDDescMap&) {
|
||||
return true;
|
||||
}
|
||||
} //unnamed namespace
|
||||
|
@ -77,7 +77,7 @@ int main (int parArgc, char* parArgv[]) {
|
|||
|
||||
const auto ids = vm["groupid"].as<std::vector<uint32_t>>();
|
||||
auto confirm_func = (vm.count("confirm") ? &always_delete : &confirm_delete);
|
||||
din::delete_group_from_db(settings.db, ids, confirm_func);
|
||||
dinbpostgres::delete_group_from_db(settings.db, ids, confirm_func);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <iterator>
|
||||
#include <algorithm>
|
||||
|
||||
namespace din {
|
||||
namespace dinbpostgres {
|
||||
std::ostream& operator<< (std::ostream& parStream, const LocatedItem& parItem) {
|
||||
parStream << parItem.group_id << '\t' << parItem.id << '\t' << parItem.path;
|
||||
return parStream;
|
||||
|
@ -41,7 +41,7 @@ namespace din {
|
|||
'\t' << parItem.files_count << '\t' << dircount;
|
||||
return parStream;
|
||||
}
|
||||
} //namespace din
|
||||
} //namespace dinbpostgres
|
||||
|
||||
namespace {
|
||||
std::vector<boost::string_ref> extract_tags (const boost::program_options::variables_map& parVM) {
|
||||
|
@ -81,22 +81,22 @@ int main (int parArgc, char* parArgv[]) {
|
|||
}
|
||||
|
||||
if (vm.count("set")) {
|
||||
const auto results = din::locate_sets_in_db(settings.db, vm["substring"].as<std::string>(), not not vm.count("case-insensitive"));
|
||||
std::copy(results.begin(), results.end(), std::ostream_iterator<din::LocatedSet>(std::cout, "\n"));
|
||||
const auto results = dinbpostgres::locate_sets_in_db(settings.db, vm["substring"].as<std::string>(), not not vm.count("case-insensitive"));
|
||||
std::copy(results.begin(), results.end(), std::ostream_iterator<dinbpostgres::LocatedSet>(std::cout, "\n"));
|
||||
}
|
||||
else {
|
||||
std::vector<din::LocatedItem> results;
|
||||
std::vector<dinbpostgres::LocatedItem> results;
|
||||
const std::vector<boost::string_ref> tags = extract_tags(vm);
|
||||
|
||||
if (vm.count("byhash")) {
|
||||
const auto hash = din::hash(vm["substring"].as<std::string>());
|
||||
results = din::locate_in_db(settings.db, hash, tags);
|
||||
results = dinbpostgres::locate_in_db(settings.db, hash, tags);
|
||||
}
|
||||
else {
|
||||
const auto search_regex = g2r::convert(vm["substring"].as<std::string>(), not vm.count("case-insensitive"));
|
||||
results = din::locate_in_db(settings.db, search_regex, tags);
|
||||
results = dinbpostgres::locate_in_db(settings.db, search_regex, tags);
|
||||
}
|
||||
std::copy(results.begin(), results.end(), std::ostream_iterator<din::LocatedItem>(std::cout, "\n"));
|
||||
std::copy(results.begin(), results.end(), std::ostream_iterator<dinbpostgres::LocatedItem>(std::cout, "\n"));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ add_executable(${PROJECT_NAME}
|
|||
commandline.cpp
|
||||
commandprocessor.cpp
|
||||
entrypath.cpp
|
||||
dbsource.cpp
|
||||
linereader.cpp
|
||||
listdircontent.cpp
|
||||
)
|
||||
|
@ -17,6 +16,7 @@ target_include_directories(${PROJECT_NAME}
|
|||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE ${bare_name}-if
|
||||
PRIVATE ${bare_name}-common
|
||||
PRIVATE ${bare_name}-backend-postgresql
|
||||
)
|
||||
|
||||
target_compile_features(${PROJECT_NAME}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include "listdircontent.hpp"
|
||||
#include "entrypath.hpp"
|
||||
#include "dbsource.hpp"
|
||||
#include "backends/postgresql/dbsource.hpp"
|
||||
#include "helpers/infix_iterator.hpp"
|
||||
#include <cassert>
|
||||
#include <utility>
|
||||
|
@ -68,7 +68,7 @@ namespace din {
|
|||
}
|
||||
} //unnamed namespace
|
||||
|
||||
ListDirContent::ListDirContent (DBSource* parDB) :
|
||||
ListDirContent::ListDirContent (dinbpostgres::DBSource* parDB) :
|
||||
m_cache(g_max_cached_lists),
|
||||
m_db(parDB)
|
||||
{
|
||||
|
@ -86,13 +86,13 @@ namespace din {
|
|||
//Requested item is not cached, so we need to query the db now
|
||||
if (parDir.points_to_group()) {
|
||||
auto sets_ids = m_db->sets();
|
||||
auto sets_info = m_db->set_details<SetDetail_ID, SetDetail_Desc, SetDetail_CreeationDate>(sets_ids);
|
||||
auto sets_info = m_db->set_details<dinbpostgres::SetDetail_ID, dinbpostgres::SetDetail_Desc, dinbpostgres::SetDetail_CreeationDate>(sets_ids);
|
||||
m_cache.push_back(std::make_pair(curr_path, db_result_to_vec(sets_info)));
|
||||
}
|
||||
else {
|
||||
auto path_prefix = parDir.file_path();
|
||||
const auto set_id = parDir.group_id();
|
||||
auto files_info = m_db->file_details<FileDetail_Path>(set_id, parDir.level() + 1, path_prefix);
|
||||
auto files_info = m_db->file_details<dinbpostgres::FileDetail_Path>(set_id, parDir.level() + 1, path_prefix);
|
||||
m_cache.push_back(std::make_pair(curr_path, db_result_to_vec(files_info)));
|
||||
}
|
||||
return last_cached_item(curr_path);
|
||||
|
|
|
@ -23,15 +23,18 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace dinbpostgres {
|
||||
class DBSource;
|
||||
} //namespace dinbpostgres
|
||||
|
||||
namespace din {
|
||||
class EntryPath;
|
||||
class DBSource;
|
||||
|
||||
class ListDirContent {
|
||||
using ListType = std::vector<std::string>;
|
||||
using CachedItemType = std::pair<std::string, ListType>;
|
||||
public:
|
||||
explicit ListDirContent ( DBSource* parDB );
|
||||
explicit ListDirContent ( dinbpostgres::DBSource* parDB );
|
||||
~ListDirContent ( void ) noexcept = default;
|
||||
|
||||
const ListType& ls ( const EntryPath& parDir ) const;
|
||||
|
@ -41,7 +44,7 @@ namespace din {
|
|||
const ListType& last_cached_item ( const std::string& parCurrPath ) const;
|
||||
|
||||
mutable boost::circular_buffer<CachedItemType> m_cache;
|
||||
DBSource* m_db;
|
||||
dinbpostgres::DBSource* m_db;
|
||||
};
|
||||
} //namespace din
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "commandprocessor.hpp"
|
||||
#include "dindexer-common/settings.hpp"
|
||||
#include "entrypath.hpp"
|
||||
#include "dbsource.hpp"
|
||||
#include "backends/postgresql/dbsource.hpp"
|
||||
#include "dindexerConfig.h"
|
||||
#include "linereader.hpp"
|
||||
#include "listdircontent.hpp"
|
||||
|
@ -31,7 +31,7 @@
|
|||
#include <boost/range/algorithm/copy.hpp>
|
||||
|
||||
namespace {
|
||||
void do_navigation ( din::DBSource& parDB );
|
||||
void do_navigation ( dinbpostgres::DBSource& parDB );
|
||||
|
||||
bool on_exit ( void );
|
||||
void on_pwd ( const din::EntryPath& parDirMan );
|
||||
|
@ -61,7 +61,7 @@ int main (int parArgc, char* parArgv[]) {
|
|||
}
|
||||
}
|
||||
|
||||
din::DBSource db_source(settings.db);
|
||||
dinbpostgres::DBSource db_source(settings.db);
|
||||
|
||||
do_navigation(db_source);
|
||||
return 0;
|
||||
|
@ -81,7 +81,7 @@ namespace {
|
|||
boost::copy(ls_result, std::ostream_iterator<std::string>(std::cout, "\n"));
|
||||
}
|
||||
|
||||
void do_navigation (din::DBSource& parDB) {
|
||||
void do_navigation (dinbpostgres::DBSource& parDB) {
|
||||
const std::string prompt;
|
||||
din::ListDirContent ls(&parDB);
|
||||
din::LineReader lines(&ls);
|
||||
|
@ -92,7 +92,7 @@ namespace {
|
|||
din::EntryPath dir_man;
|
||||
proc.add_command("exit", &on_exit, 0);
|
||||
proc.add_command("cd", std::function<void(const std::string&)>(std::bind(&din::EntryPath::push_piece, &dir_man, std::placeholders::_1)), 1);
|
||||
proc.add_command("disconnect", std::function<void()>(std::bind(&din::DBSource::disconnect, &parDB)), 0);
|
||||
proc.add_command("disconnect", std::function<void()>(std::bind(&dinbpostgres::DBSource::disconnect, &parDB)), 0);
|
||||
proc.add_command("pwd", std::function<void()>(std::bind(&on_pwd, std::ref(dir_man))), 0);
|
||||
proc.add_command("ls", std::function<void()>(std::bind(on_ls, std::ref(ls), std::ref(dir_man))), 0);
|
||||
do {
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
#endif
|
||||
|
||||
namespace {
|
||||
bool add_to_db ( const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordDataFull& parSet, const dinlib::SettingsDB& parDBSettings, bool parForce=false );
|
||||
bool add_to_db ( const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordDataFull& parSet, const dinbpostgres::Settings& parDBSettings, bool parForce=false );
|
||||
#if defined(WITH_PROGRESS_FEEDBACK)
|
||||
void print_progress ( const boost::string_ref parPath, uint64_t parFileBytes, uint64_t parTotalBytes, uint32_t parFileNum, std::size_t& parClearCount );
|
||||
#endif
|
||||
|
@ -115,7 +115,7 @@ int main (int parArgc, char* parArgv[]) {
|
|||
}
|
||||
|
||||
namespace {
|
||||
bool add_to_db (const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordDataFull& parSet, const dinlib::SettingsDB& parDBSettings, bool parForce) {
|
||||
bool add_to_db (const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordDataFull& parSet, const dinbpostgres::Settings& parDBSettings, bool parForce) {
|
||||
using mchlib::FileRecordData;
|
||||
using mchlib::SetRecordDataFull;
|
||||
using mchlib::SetRecordData;
|
||||
|
@ -124,7 +124,7 @@ namespace {
|
|||
const auto& first_hash = parData.front().hash;
|
||||
FileRecordData itm;
|
||||
SetRecordDataFull set;
|
||||
const bool already_in_db = din::read_from_db(itm, set, parDBSettings, first_hash);
|
||||
const bool already_in_db = dinbpostgres::read_from_db(itm, set, parDBSettings, first_hash);
|
||||
if (already_in_db) {
|
||||
return false;
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ namespace {
|
|||
const auto app_signature = dinlib::dindexer_signature();
|
||||
const auto lib_signature = mchlib::lib_signature();
|
||||
const std::string signature = std::string(app_signature.data(), app_signature.size()) + "/" + std::string(lib_signature.data(), lib_signature.size());
|
||||
din::write_to_db(parDBSettings, parData, set_data, signature);
|
||||
dinbpostgres::write_to_db(parDBSettings, parData, set_data, signature);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,8 +47,8 @@ namespace {
|
|||
return retval;
|
||||
}
|
||||
|
||||
din::OwnerSetInfo make_owner_set_info (const boost::program_options::variables_map& parVM) {
|
||||
din::OwnerSetInfo set_info;
|
||||
dinbpostgres::OwnerSetInfo make_owner_set_info (const boost::program_options::variables_map& parVM) {
|
||||
dinbpostgres::OwnerSetInfo set_info;
|
||||
if (parVM.count("set")) {
|
||||
set_info.is_valid = true;
|
||||
set_info.group_id = parVM["set"].as<uint32_t>();
|
||||
|
@ -60,11 +60,11 @@ namespace {
|
|||
return set_info;
|
||||
}
|
||||
|
||||
int tag_files (const dinlib::SettingsDB& parDB, TaggingMode parMode, const boost::program_options::variables_map& parVM, const std::vector<boost::string_ref>& parTags) {
|
||||
int tag_files (const dinbpostgres::Settings& parDB, TaggingMode parMode, const boost::program_options::variables_map& parVM, const std::vector<boost::string_ref>& parTags) {
|
||||
using boost::lexical_cast;
|
||||
using boost::string_ref;
|
||||
|
||||
const din::OwnerSetInfo set_info = make_owner_set_info(parVM);
|
||||
const dinbpostgres::OwnerSetInfo set_info = make_owner_set_info(parVM);
|
||||
|
||||
switch (parMode) {
|
||||
case TaggingMode::ID:
|
||||
|
@ -73,14 +73,14 @@ namespace {
|
|||
std::vector<uint64_t> ids;
|
||||
ids.reserve(ids_string.size());
|
||||
std::transform(ids_string.begin(), ids_string.end(), std::back_inserter(ids), &lexical_cast<uint64_t, string_ref>);
|
||||
din::tag_files(parDB, ids, parTags, set_info);
|
||||
dinbpostgres::tag_files(parDB, ids, parTags, set_info);
|
||||
return 0;
|
||||
}
|
||||
|
||||
case TaggingMode::Glob:
|
||||
{
|
||||
const auto regexes(globs_to_regex_list(parVM["globs"].as<std::vector<std::string>>()));
|
||||
din::tag_files(parDB, regexes, parTags, set_info);
|
||||
dinbpostgres::tag_files(parDB, regexes, parTags, set_info);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ namespace {
|
|||
}
|
||||
}
|
||||
|
||||
int delete_tags (const dinlib::SettingsDB& parDB, TaggingMode parMode, const boost::program_options::variables_map& parVM, const std::vector<boost::string_ref>& parTags) {
|
||||
int delete_tags (const dinbpostgres::Settings& parDB, TaggingMode parMode, const boost::program_options::variables_map& parVM, const std::vector<boost::string_ref>& parTags) {
|
||||
using boost::lexical_cast;
|
||||
using boost::string_ref;
|
||||
|
||||
|
@ -104,9 +104,9 @@ namespace {
|
|||
ids.reserve(ids_string.size());
|
||||
std::transform(ids_string.begin(), ids_string.end(), std::back_inserter(ids), &lexical_cast<uint64_t, string_ref>);
|
||||
if (parVM.count("alltags"))
|
||||
din::delete_all_tags(parDB, ids, make_owner_set_info(parVM));
|
||||
dinbpostgres::delete_all_tags(parDB, ids, make_owner_set_info(parVM));
|
||||
else
|
||||
din::delete_tags(parDB, ids, parTags, make_owner_set_info(parVM));
|
||||
dinbpostgres::delete_tags(parDB, ids, parTags, make_owner_set_info(parVM));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -114,9 +114,9 @@ namespace {
|
|||
{
|
||||
const auto regexes(globs_to_regex_list(parVM["globs"].as<std::vector<std::string>>()));
|
||||
if (parVM.count("alltags"))
|
||||
din::delete_all_tags(parDB, regexes, make_owner_set_info(parVM));
|
||||
dinbpostgres::delete_all_tags(parDB, regexes, make_owner_set_info(parVM));
|
||||
else
|
||||
din::delete_tags(parDB, regexes, parTags, make_owner_set_info(parVM));
|
||||
dinbpostgres::delete_tags(parDB, regexes, parTags, make_owner_set_info(parVM));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue