From 913cdbd59def89b1f76259dd8a43479092b70de8 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Thu, 21 Jan 2016 20:30:38 +0000 Subject: [PATCH] Add app_name column to sets. --- dindexer.sql.in | 5 ++- include/dindexer-common/common_info.hpp | 27 +++++++++++++ include/dindexer-machinery/machinery_info.hpp | 27 +++++++++++++ include/helpers/stringize.h | 24 ++++++++++++ src/common/CMakeLists.txt | 1 + src/common/commandline.cpp | 4 +- src/common/common_info.cpp | 38 +++++++++++++++++++ src/machinery/CMakeLists.txt | 1 + src/machinery/machinery_info.cpp | 33 ++++++++++++++++ src/scan/dbbackend.cpp | 11 ++++-- src/scan/dbbackend.hpp | 4 +- src/scan/main.cpp | 9 ++++- 12 files changed, 171 insertions(+), 13 deletions(-) create mode 100644 include/dindexer-common/common_info.hpp create mode 100644 include/dindexer-machinery/machinery_info.hpp create mode 100644 include/helpers/stringize.h create mode 100644 src/common/common_info.cpp create mode 100644 src/machinery/machinery_info.cpp diff --git a/dindexer.sql.in b/dindexer.sql.in index ed0e1f6..a776266 100644 --- a/dindexer.sql.in +++ b/dindexer.sql.in @@ -4,7 +4,7 @@ -- Dumped from database version 9.4.5 -- Dumped by pg_dump version 9.4.5 --- Started on 2016-01-07 15:10:56 GMT +-- Started on 2016-01-21 20:29:42 GMT SET statement_timeout = 0; SET lock_timeout = 0; @@ -141,6 +141,7 @@ CREATE TABLE sets ( type character(1) DEFAULT 'D'::bpchar NOT NULL, disk_number integer DEFAULT 0 NOT NULL, creation timestamp with time zone DEFAULT now() NOT NULL, + app_name character varying 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))) ); @@ -282,7 +283,7 @@ GRANT ALL ON SCHEMA public TO postgres; GRANT ALL ON SCHEMA public TO PUBLIC; --- Completed on 2016-01-07 15:11:05 GMT +-- Completed on 2016-01-21 20:29:44 GMT -- -- PostgreSQL database dump complete diff --git a/include/dindexer-common/common_info.hpp b/include/dindexer-common/common_info.hpp new file mode 100644 index 0000000..c3c875c --- /dev/null +++ b/include/dindexer-common/common_info.hpp @@ -0,0 +1,27 @@ +/* Copyright 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 . + */ + +#ifndef idD68F614BAF5D480A90EE41731BDEE822 +#define idD68F614BAF5D480A90EE41731BDEE822 + +#include + +namespace dinlib { + boost::string_ref dindexer_signature ( void ); +} //namespace dinlib + +#endif diff --git a/include/dindexer-machinery/machinery_info.hpp b/include/dindexer-machinery/machinery_info.hpp new file mode 100644 index 0000000..ae0e957 --- /dev/null +++ b/include/dindexer-machinery/machinery_info.hpp @@ -0,0 +1,27 @@ +/* Copyright 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 . + */ + +#ifndef id32001138F12F4B5797C5883CDE8C2BDF +#define id32001138F12F4B5797C5883CDE8C2BDF + +#include + +namespace mchlib { + boost::string_ref lib_signature ( void ); +} //namespace mchlib + +#endif diff --git a/include/helpers/stringize.h b/include/helpers/stringize.h new file mode 100644 index 0000000..c6c29bd --- /dev/null +++ b/include/helpers/stringize.h @@ -0,0 +1,24 @@ +/* Copyright 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 . + */ + +#ifndef id8B9FF1807C05459DAE8CD05312147416 +#define id8B9FF1807C05459DAE8CD05312147416 + +#define STRINGIZE_IMPL(s) #s +#define STRINGIZE(s) STRINGIZE_IMPL(s) + +#endif diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 765a2ac..a3f5ef8 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -5,6 +5,7 @@ add_library(${PROJECT_NAME} mediatypes.cpp settings.cpp validationerror.cpp + common_info.cpp ) target_include_directories(${PROJECT_NAME} diff --git a/src/common/commandline.cpp b/src/common/commandline.cpp index 4b81483..28c3b8c 100644 --- a/src/common/commandline.cpp +++ b/src/common/commandline.cpp @@ -18,13 +18,11 @@ #include "dindexer-common/commandline.hpp" #include "dindexerConfig.h" #include "helpers/lengthof.h" +#include "helpers/stringize.h" #include #include #include -#define STRINGIZE_IMPL(s) #s -#define STRINGIZE(s) STRINGIZE_IMPL(s) - namespace po = boost::program_options; namespace dinlib { diff --git a/src/common/common_info.cpp b/src/common/common_info.cpp new file mode 100644 index 0000000..a85353b --- /dev/null +++ b/src/common/common_info.cpp @@ -0,0 +1,38 @@ +/* Copyright 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 . + */ + +#include "dindexer-common/common_info.hpp" +#include "dindexerConfig.h" +#include "helpers/stringize.h" + +namespace dinlib { + namespace { + const char* const g_signature_string = + PROGRAM_NAME "_v" + STRINGIZE(VERSION_MAJOR) "." + STRINGIZE(VERSION_MINOR) "." + STRINGIZE(VERSION_PATCH) +#if VERSION_BETA + "b" +#endif + ; + } //unnamed namespace + + boost::string_ref dindexer_signature() { + return boost::string_ref(g_signature_string); + } +} //namespace dinlib diff --git a/src/machinery/CMakeLists.txt b/src/machinery/CMakeLists.txt index 031804b..9bdad4a 100644 --- a/src/machinery/CMakeLists.txt +++ b/src/machinery/CMakeLists.txt @@ -12,6 +12,7 @@ add_library(${PROJECT_NAME} SHARED filesearcher.cpp discinfo.cpp mediatype.cpp + machinery_info.cpp ) #target_include_directories(${PROJECT_NAME} diff --git a/src/machinery/machinery_info.cpp b/src/machinery/machinery_info.cpp new file mode 100644 index 0000000..5d38576 --- /dev/null +++ b/src/machinery/machinery_info.cpp @@ -0,0 +1,33 @@ +/* Copyright 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 . + */ + +#include "dindexer-machinery/machinery_info.hpp" +#include "dindexerConfig.h" +#include "helpers/stringize.h" + +namespace mchlib { + boost::string_ref lib_signature() { + return boost::string_ref("machinery_v" + STRINGIZE(VERSION_MAJOR) "." + STRINGIZE(VERSION_MINOR) "." + STRINGIZE(VERSION_PATCH) +#if VERSION_BETA + "b" +#endif + ); + } +} //namespace mchlib diff --git a/src/scan/dbbackend.cpp b/src/scan/dbbackend.cpp index f45e081..4175d5d 100644 --- a/src/scan/dbbackend.cpp +++ b/src/scan/dbbackend.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015, Michele Santullo +/* Copyright 2016, Michele Santullo * This file is part of "dindexer". * * "dindexer" is free software: you can redistribute it and/or modify @@ -82,7 +82,7 @@ namespace din { return true; } - void write_to_db (const dinlib::SettingsDB& parDB, const std::vector& parData, const mchlib::SetRecordData& parSetData) { + void write_to_db (const dinlib::SettingsDB& parDB, const std::vector& parData, const mchlib::SetRecordData& parSetData, const std::string& parSignature) { using std::chrono::system_clock; using boost::lexical_cast; @@ -96,9 +96,12 @@ namespace din { conn.query("BEGIN;"); uint32_t new_group_id; { - auto id_res = conn.query("INSERT INTO \"sets\" (\"desc\",\"type\") VALUES ($1, $2) RETURNING \"id\";", + auto id_res = conn.query("INSERT INTO \"sets\" " + "(\"desc\",\"type\", \"app_name\") " + "VALUES ($1, $2) RETURNING \"id\";", parSetData.name, - std::string(1, parSetData.type) + std::string(1, parSetData.type), + parSignature ); assert(id_res.size() == 1); assert(id_res[0].size() == 1); diff --git a/src/scan/dbbackend.hpp b/src/scan/dbbackend.hpp index 17ea092..72657ab 100644 --- a/src/scan/dbbackend.hpp +++ b/src/scan/dbbackend.hpp @@ -1,4 +1,4 @@ -/* Copyright 2015, Michele Santullo +/* Copyright 2016, Michele Santullo * This file is part of "dindexer". * * "dindexer" is free software: you can redistribute it and/or modify @@ -34,7 +34,7 @@ namespace mchlib { } //namespace mchlib namespace din { - void write_to_db ( const dinlib::SettingsDB& parDB, const std::vector& parData, const mchlib::SetRecordData& parSetData ); + void write_to_db ( const dinlib::SettingsDB& parDB, const std::vector& 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 diff --git a/src/scan/main.cpp b/src/scan/main.cpp index 3e99bb8..533fd5b 100644 --- a/src/scan/main.cpp +++ b/src/scan/main.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015, Michele Santullo +/* Copyright 2016, Michele Santullo * This file is part of "dindexer". * * "dindexer" is free software: you can redistribute it and/or modify @@ -23,6 +23,8 @@ #include "dindexerConfig.h" #include "dindexer-machinery/filesearcher.hpp" #include "dindexer-machinery/indexer.hpp" +#include "dindexer-machinery/machinery_info.hpp" +#include "dindexer-common/common_info.hpp" #include "dindexer-common/settings.hpp" #include "commandline.hpp" #include "dbbackend.hpp" @@ -196,7 +198,10 @@ namespace { } SetRecordData set_data {parSetName, parType}; - din::write_to_db(parDBSettings, parData, set_data); + 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); return true; } } //unnamed namespace