1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-08-17 15:19:48 +00:00

Store mime type and charset in the db.

This commit is contained in:
King_DuckZ 2016-01-06 02:18:42 +00:00
parent 839b9dd49a
commit 6edfb08383
3 changed files with 41 additions and 17 deletions

View file

@ -134,6 +134,11 @@ namespace mchlib {
if (parIgnoreErrors) {
it_entry->unreadable = true;
it_entry->hash = HashType {};
if (it_entry->mime_full.get().empty()) {
it_entry->mime_full = "unknown";
it_entry->mime_type = boost::string_ref(it_entry->mime_full.get());
it_entry->mime_charset = boost::string_ref(it_entry->mime_full.get());
}
}
else {
throw e;
@ -152,6 +157,12 @@ namespace mchlib {
std::cout << "Final hash for dir " << parCurrDir << " is " << tiger_to_string(curr_entry_it->hash) << '\n';
#endif
curr_entry_it->hash_valid = true;
{
curr_entry_it->mime_full = parMime.analyze(curr_entry_it->path);
auto mime_pair = split_mime(curr_entry_it->mime_full);
curr_entry_it->mime_type = mime_pair.first;
curr_entry_it->mime_charset = mime_pair.second;
}
}
template <bool FileTrue=true>

View file

@ -104,8 +104,9 @@ namespace din {
for (std::size_t z = 0; z < parData.size(); ++z) {
const std::string query = "INSERT INTO \"files\" (path, hash, "
"level, group_id, is_directory, is_symlink, size, "
"access_time, modify_time, is_hash_valid, unreadable) VALUES "
"($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);";
"access_time, modify_time, is_hash_valid, unreadable, "
"mimetype, charset) VALUES "
"($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13);";
const auto& itm = parData[z];
conn.query(query,
@ -119,7 +120,9 @@ namespace din {
system_clock::from_time_t(itm.atime),
system_clock::from_time_t(itm.mtime),
itm.hash_valid,
itm.unreadable
itm.unreadable,
std::string(itm.mime_type.data(), itm.mime_type.size()),
std::string(itm.mime_charset.data(), itm.mime_charset.size())
);
}
conn.query("COMMIT;");