From 7117ff7be266f934e97a5430b4a6023c65b3af10 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Sat, 4 Jun 2016 01:03:20 +0200 Subject: [PATCH] Save and read label and uuid to the database --- dindexer.sql.in | 6 ++++-- include/backends/db_backend.hpp | 4 ++-- include/dindexer-machinery/recorddata.hpp | 2 ++ src/backends/postgresql/backend_postgresql.cpp | 11 ++++++++--- src/backends/postgresql/backend_postgresql.hpp | 4 ++-- src/backends/postgresql/navigate.cpp | 4 +++- src/backends/postgresql/navigate.hpp | 4 +++- src/backends/postgresql/scan.cpp | 14 +++++++++----- src/backends/postgresql/scan.hpp | 2 +- src/machinery/scantask/mediatype.cpp | 7 +++++++ src/scan/main.cpp | 4 +--- 11 files changed, 42 insertions(+), 20 deletions(-) diff --git a/dindexer.sql.in b/dindexer.sql.in index a5a905a..355ba9d 100644 --- a/dindexer.sql.in +++ b/dindexer.sql.in @@ -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 diff --git a/include/backends/db_backend.hpp b/include/backends/db_backend.hpp index 07aec9c..a87596d 100644 --- a/include/backends/db_backend.hpp +++ b/include/backends/db_backend.hpp @@ -74,7 +74,7 @@ namespace dindb { virtual void delete_group ( const std::vector& parIDs, ConfirmDeleCallback parConf ) = 0; - virtual void write_files ( const std::vector& parData, const mchlib::SetRecordData& parSetData, const std::string& parSignature ) = 0; + virtual void write_files ( const std::vector& 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 locate_in_db ( const std::string& parSearch, const TagList& parTags ) = 0; @@ -83,7 +83,7 @@ namespace dindb { virtual std::vector locate_sets_in_db ( const std::string& parSearch, const std::vector& parSets, bool parCaseInsensitive ) = 0; virtual std::vector find_all_sets ( void ) = 0; - virtual std::vector> find_set_details ( const std::vector& parSets ) = 0; + virtual std::vector> find_set_details ( const std::vector& parSets ) = 0; virtual std::vector> find_file_details ( GroupIDType parSetID, uint16_t parLevel, boost::string_ref parDir ) = 0; virtual std::vector find_paths_starting_by ( GroupIDType parGroupID, uint16_t parLevel, boost::string_ref parPath ) = 0; }; diff --git a/include/dindexer-machinery/recorddata.hpp b/include/dindexer-machinery/recorddata.hpp index 3afc127..29bb653 100644 --- a/include/dindexer-machinery/recorddata.hpp +++ b/include/dindexer-machinery/recorddata.hpp @@ -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; }; diff --git a/src/backends/postgresql/backend_postgresql.cpp b/src/backends/postgresql/backend_postgresql.cpp index 68577ec..933a9ce 100644 --- a/src/backends/postgresql/backend_postgresql.cpp +++ b/src/backends/postgresql/backend_postgresql.cpp @@ -117,7 +117,7 @@ namespace dindb { dindb::delete_group_from_db(*m_conn, parIDs, parConf); } - void BackendPostgreSql::write_files (const std::vector& parData, const mchlib::SetRecordData& parSetData, const std::string& parSignature) { + void BackendPostgreSql::write_files (const std::vector& 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> BackendPostgreSql::find_set_details (const std::vector& parSets) { - return dindb::find_set_details(*m_conn, parSets); + std::vector> BackendPostgreSql::find_set_details (const std::vector& parSets) { + return dindb::find_set_details< + dindb::SetDetail_ID, + dindb::SetDetail_Desc, + dindb::SetDetail_CreeationDate, + dindb::SetDetail_DiskLabel + >(*m_conn, parSets); } std::vector> BackendPostgreSql::find_file_details (GroupIDType parSetID, uint16_t parLevel, boost::string_ref parDir) { diff --git a/src/backends/postgresql/backend_postgresql.hpp b/src/backends/postgresql/backend_postgresql.hpp index 103c532..3b0b872 100644 --- a/src/backends/postgresql/backend_postgresql.hpp +++ b/src/backends/postgresql/backend_postgresql.hpp @@ -46,7 +46,7 @@ namespace dindb { virtual void delete_group ( const std::vector& parIDs, ConfirmDeleCallback parConf ) override; - virtual void write_files ( const std::vector& parData, const mchlib::SetRecordData& parSetData, const std::string& parSignature ) override; + virtual void write_files ( const std::vector& 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 locate_in_db ( const std::string& parSearch, const TagList& parTags ) override; @@ -55,7 +55,7 @@ namespace dindb { virtual std::vector locate_sets_in_db ( const std::string& parSearch, const std::vector& parSets, bool parCaseInsensitive ) override; virtual std::vector find_all_sets ( void ) override; - virtual std::vector> find_set_details ( const std::vector& parSets ) override; + virtual std::vector> find_set_details ( const std::vector& parSets ) override; virtual std::vector> find_file_details ( GroupIDType parSetID, uint16_t parLevel, boost::string_ref parDir ) override; virtual std::vector find_paths_starting_by ( GroupIDType parGroupID, uint16_t parLevel, boost::string_ref parPath ) override; diff --git a/src/backends/postgresql/navigate.cpp b/src/backends/postgresql/navigate.cpp index 43af1f2..ae06f75 100644 --- a/src/backends/postgresql/navigate.cpp +++ b/src/backends/postgresql/navigate.cpp @@ -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"}, diff --git a/src/backends/postgresql/navigate.hpp b/src/backends/postgresql/navigate.hpp index d52ecd7..cc732ba 100644 --- a/src/backends/postgresql/navigate.hpp +++ b/src/backends/postgresql/navigate.hpp @@ -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 { diff --git a/src/backends/postgresql/scan.cpp b/src/backends/postgresql/scan.cpp index fd533ed..ca5e09b 100644 --- a/src/backends/postgresql/scan.cpp +++ b/src/backends/postgresql/scan.cpp @@ -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(row["type"]); parSet.name = row["desc"]; parSet.disk_number = lexical_cast(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& parData, const mchlib::SetRecordData& parSetData, const std::string& parSignature) { + void write_to_db (pq::Connection& parDB, const std::vector& 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); diff --git a/src/backends/postgresql/scan.hpp b/src/backends/postgresql/scan.hpp index 72521d7..b8f7482 100644 --- a/src/backends/postgresql/scan.hpp +++ b/src/backends/postgresql/scan.hpp @@ -36,7 +36,7 @@ namespace pq { namespace dindb { struct Settings;; - void write_to_db ( pq::Connection& parDB, const std::vector& parData, const mchlib::SetRecordData& parSetData, const std::string& parSignature ); + void write_to_db ( pq::Connection& parDB, const std::vector& 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 diff --git a/src/machinery/scantask/mediatype.cpp b/src/machinery/scantask/mediatype.cpp index 1374c3f..ddd244a 100644 --- a/src/machinery/scantask/mediatype.cpp +++ b/src/machinery/scantask/mediatype.cpp @@ -21,6 +21,7 @@ # include "dindexer-machinery/mediatype.hpp" #endif #include "dindexer-machinery/recorddata.hpp" +#include "discinfo.hpp" #include 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 diff --git a/src/scan/main.cpp b/src/scan/main.cpp index e6e8e3f..207feec 100644 --- a/src/scan/main.cpp +++ b/src/scan/main.cpp @@ -118,7 +118,6 @@ namespace { bool add_to_db (const std::vector& 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; }