1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2024-11-29 01:33:46 +00:00

Save and read label and uuid to the database

This commit is contained in:
King_DuckZ 2016-06-04 01:03:20 +02:00
parent 55a61526dc
commit 7117ff7be2
11 changed files with 42 additions and 20 deletions

View file

@ -5,7 +5,7 @@
-- Dumped from database version 9.5.2
-- Dumped by pg_dump version 9.5.2
-- Started on 2016-05-18 00:47:01 CEST
-- Started on 2016-06-03 20:30:32 CEST
SET statement_timeout = 0;
SET lock_timeout = 0;
@ -160,6 +160,8 @@ CREATE TABLE sets (
creation timestamp with time zone DEFAULT now() NOT NULL,
app_name character varying NOT NULL,
content_type character(1) DEFAULT 'G'::bpchar NOT NULL,
disk_label text NOT NULL,
fs_uuid text NOT NULL,
CONSTRAINT chk_sets_type CHECK (((type = 'C'::bpchar) OR (type = 'D'::bpchar) OR (type = 'V'::bpchar) OR (type = 'B'::bpchar) OR (type = 'F'::bpchar) OR (type = 'H'::bpchar) OR (type = 'Z'::bpchar) OR (type = 'O'::bpchar)))
);
@ -309,7 +311,7 @@ GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO PUBLIC;
-- Completed on 2016-05-18 00:47:01 CEST
-- Completed on 2016-06-03 20:30:33 CEST
--
-- PostgreSQL database dump complete

View file

@ -74,7 +74,7 @@ namespace dindb {
virtual void delete_group ( const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf ) = 0;
virtual void write_files ( const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordData& parSetData, const std::string& parSignature ) = 0;
virtual void write_files ( const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordDataFull& parSetData, const std::string& parSignature ) = 0;
virtual bool search_file_by_hash ( mchlib::FileRecordData& parItem, mchlib::SetRecordDataFull& parSet, const mchlib::TigerHash& parHash ) = 0;
virtual std::vector<LocatedItem> locate_in_db ( const std::string& parSearch, const TagList& parTags ) = 0;
@ -83,7 +83,7 @@ namespace dindb {
virtual std::vector<LocatedSet> locate_sets_in_db ( const std::string& parSearch, const std::vector<GroupIDType>& parSets, bool parCaseInsensitive ) = 0;
virtual std::vector<GroupIDType> find_all_sets ( void ) = 0;
virtual std::vector<dinhelp::MaxSizedArray<std::string, 3>> find_set_details ( const std::vector<GroupIDType>& parSets ) = 0;
virtual std::vector<dinhelp::MaxSizedArray<std::string, 4>> find_set_details ( const std::vector<GroupIDType>& parSets ) = 0;
virtual std::vector<dinhelp::MaxSizedArray<std::string, 1>> find_file_details ( GroupIDType parSetID, uint16_t parLevel, boost::string_ref parDir ) = 0;
virtual std::vector<std::string> find_paths_starting_by ( GroupIDType parGroupID, uint16_t parLevel, boost::string_ref parPath ) = 0;
};

View file

@ -138,6 +138,8 @@ namespace mchlib {
struct SetRecordDataFull : public SetRecordData {
std::string name;
std::string disk_label;
std::string fs_uuid;
uint32_t disk_number;
};

View file

@ -117,7 +117,7 @@ namespace dindb {
dindb::delete_group_from_db(*m_conn, parIDs, parConf);
}
void BackendPostgreSql::write_files (const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordData& parSetData, const std::string& parSignature) {
void BackendPostgreSql::write_files (const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordDataFull& parSetData, const std::string& parSignature) {
dindb::write_to_db(*m_conn, parData, parSetData, parSignature);
}
@ -145,8 +145,13 @@ namespace dindb {
return dindb::find_all_sets(*m_conn);
}
std::vector<dinhelp::MaxSizedArray<std::string, 3>> BackendPostgreSql::find_set_details (const std::vector<GroupIDType>& parSets) {
return dindb::find_set_details<dindb::SetDetail_ID, dindb::SetDetail_Desc, dindb::SetDetail_CreeationDate>(*m_conn, parSets);
std::vector<dinhelp::MaxSizedArray<std::string, 4>> BackendPostgreSql::find_set_details (const std::vector<GroupIDType>& parSets) {
return dindb::find_set_details<
dindb::SetDetail_ID,
dindb::SetDetail_Desc,
dindb::SetDetail_CreeationDate,
dindb::SetDetail_DiskLabel
>(*m_conn, parSets);
}
std::vector<dinhelp::MaxSizedArray<std::string, 1>> BackendPostgreSql::find_file_details (GroupIDType parSetID, uint16_t parLevel, boost::string_ref parDir) {

View file

@ -46,7 +46,7 @@ namespace dindb {
virtual void delete_group ( const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf ) override;
virtual void write_files ( const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordData& parSetData, const std::string& parSignature ) override;
virtual void write_files ( const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordDataFull& parSetData, const std::string& parSignature ) override;
virtual bool search_file_by_hash ( mchlib::FileRecordData& parItem, mchlib::SetRecordDataFull& parSet, const mchlib::TigerHash& parHash ) override;
virtual std::vector<LocatedItem> locate_in_db ( const std::string& parSearch, const TagList& parTags ) override;
@ -55,7 +55,7 @@ namespace dindb {
virtual std::vector<LocatedSet> locate_sets_in_db ( const std::string& parSearch, const std::vector<GroupIDType>& parSets, bool parCaseInsensitive ) override;
virtual std::vector<GroupIDType> find_all_sets ( void ) override;
virtual std::vector<dinhelp::MaxSizedArray<std::string, 3>> find_set_details ( const std::vector<GroupIDType>& parSets ) override;
virtual std::vector<dinhelp::MaxSizedArray<std::string, 4>> find_set_details ( const std::vector<GroupIDType>& parSets ) override;
virtual std::vector<dinhelp::MaxSizedArray<std::string, 1>> find_file_details ( GroupIDType parSetID, uint16_t parLevel, boost::string_ref parDir ) override;
virtual std::vector<std::string> find_paths_starting_by ( GroupIDType parGroupID, uint16_t parLevel, boost::string_ref parPath ) override;

View file

@ -44,7 +44,9 @@ namespace dindb {
{SetDetail_Type, "type"},
{SetDetail_CreeationDate, "creation"},
{SetDetail_AppName, "app_name"},
{SetDetail_ID, "id"}
{SetDetail_ID, "id"},
{SetDetail_DiskLabel, "disk_label"},
{SetDetail_FSUuid, "fs_uuid"}
};
const FileDetailsMap g_file_details_map {
{FileDetail_ID, "id"},

View file

@ -44,7 +44,9 @@ namespace dindb {
SetDetail_Type = 0x02,
SetDetail_CreeationDate = 0x04,
SetDetail_AppName = 0x08,
SetDetail_ID = 0x10
SetDetail_ID = 0x10,
SetDetail_DiskLabel = 0x20,
SetDetail_FSUuid = 0x40
};
enum FileDetails {

View file

@ -64,7 +64,7 @@ namespace dindb {
{
auto resultset = parDB.query(
"SELECT \"desc\",\"type\",\"disk_number\" FROM sets WHERE \"id\"=$1;",
"SELECT \"desc\",\"type\",\"disk_number\",\"fs_uuid\",\"disk_label\" FROM sets WHERE \"id\"=$1;",
group_id
);
if (resultset.empty()) {
@ -77,11 +77,13 @@ namespace dindb {
parSet.type = lexical_cast<char>(row["type"]);
parSet.name = row["desc"];
parSet.disk_number = lexical_cast<uint32_t>(row["disk_number"]);
parSet.fs_uuid = row["fs_uuid"];
parSet.disk_label = row["disk_label"];
}
return true;
}
void write_to_db (pq::Connection& parDB, const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordData& parSetData, const std::string& parSignature) {
void write_to_db (pq::Connection& parDB, const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordDataFull& parSetData, const std::string& parSignature) {
using std::chrono::system_clock;
using boost::lexical_cast;
@ -96,12 +98,14 @@ namespace dindb {
{
auto id_res = parDB.query("INSERT INTO \"sets\" "
"(\"desc\",\"type\",\"app_name\""
",\"content_type\") "
"VALUES ($1, $2, $3, $4) RETURNING \"id\";",
",\"content_type\",\"fs_uuid\",\"disk_label\") "
"VALUES ($1, $2, $3, $4, $5, $6) RETURNING \"id\";",
parSetData.name,
boost::string_ref(&parSetData.type, 1),
parSignature,
boost::string_ref(&parSetData.content_type, 1)
boost::string_ref(&parSetData.content_type, 1),
parSetData.fs_uuid,
parSetData.disk_label
);
assert(id_res.size() == 1);
assert(id_res[0].size() == 1);

View file

@ -36,7 +36,7 @@ namespace pq {
namespace dindb {
struct Settings;;
void write_to_db ( pq::Connection& parDB, const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordData& parSetData, const std::string& parSignature );
void write_to_db ( pq::Connection& parDB, const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordDataFull& parSetData, const std::string& parSignature );
bool read_from_db ( mchlib::FileRecordData& parItem, mchlib::SetRecordDataFull& parSet, pq::Connection& parDB, const mchlib::TigerHash& parHash );
} //namespace dindb

View file

@ -21,6 +21,7 @@
# include "dindexer-machinery/mediatype.hpp"
#endif
#include "dindexer-machinery/recorddata.hpp"
#include "discinfo.hpp"
#include <utility>
namespace mchlib {
@ -57,6 +58,12 @@ namespace mchlib {
#else
data.type = media_type_to_char(m_default);
#endif
{
DiscInfo info((std::string(m_search_path)));
data.disk_label = info.label();
data.fs_uuid = info.filesystem_uuid();
}
}
} //namespace scantask
} //namespace mchlib

View file

@ -118,7 +118,6 @@ namespace {
bool add_to_db (const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordDataFull& parSet, dindb::Backend& parDB, bool parForce) {
using mchlib::FileRecordData;
using mchlib::SetRecordDataFull;
using mchlib::SetRecordData;
if (not parForce) {
const auto& first_hash = parData.front().hash;
@ -130,11 +129,10 @@ namespace {
}
}
const SetRecordData& set_data {parSet.name, parSet.type, parSet.content_type };
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());
parDB.write_files(parData, set_data, signature);
parDB.write_files(parData, parSet, signature);
return true;
}