2016-02-05 20:01:51 +00:00
|
|
|
/* Copyright 2015, 2016, Michele Santullo
|
2015-12-29 17:32:22 +00:00
|
|
|
* 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 id3CD7F105AC314540A864487E981E5A7E
|
|
|
|
#define id3CD7F105AC314540A864487E981E5A7E
|
|
|
|
|
|
|
|
#include "tiger.hpp"
|
|
|
|
#include <string>
|
|
|
|
#include <boost/utility/string_ref.hpp>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <ctime>
|
|
|
|
#include <boost/flyweight.hpp>
|
|
|
|
#include <boost/flyweight/no_locking.hpp>
|
2016-05-17 19:12:44 +00:00
|
|
|
#include <functional>
|
2015-12-29 17:32:22 +00:00
|
|
|
|
2016-01-05 12:49:27 +00:00
|
|
|
namespace mchlib {
|
2015-12-29 17:32:22 +00:00
|
|
|
struct FileRecordData {
|
|
|
|
struct MimeStringTagStruct { };
|
|
|
|
typedef boost::flyweights::tag<MimeStringTagStruct> MimeStringTag;
|
|
|
|
typedef boost::flyweight<std::string, boost::flyweights::no_locking, MimeStringTag> mime_string;
|
|
|
|
|
|
|
|
FileRecordData ( void ) = default;
|
2016-06-01 08:08:56 +00:00
|
|
|
FileRecordData ( const char* parPath, std::time_t parATime, std::time_t parMTime, uint16_t parLevel, bool parIsDir, bool parIsSymLink ) :
|
2015-12-29 17:32:22 +00:00
|
|
|
hash {},
|
2016-01-11 12:46:06 +00:00
|
|
|
abs_path(parPath),
|
2015-12-29 17:32:22 +00:00
|
|
|
mime_full(),
|
|
|
|
atime(parATime),
|
|
|
|
mtime(parMTime),
|
|
|
|
size(0),
|
|
|
|
level(parLevel),
|
2016-05-17 18:21:44 +00:00
|
|
|
path_offset(0),
|
2016-05-17 19:12:44 +00:00
|
|
|
mime_type_offset(0),
|
|
|
|
mime_type_length(0),
|
|
|
|
mime_charset_offset(0),
|
|
|
|
mime_charset_length(0),
|
2015-12-29 17:32:22 +00:00
|
|
|
is_directory(parIsDir),
|
|
|
|
is_symlink(parIsSymLink),
|
|
|
|
unreadable(false),
|
|
|
|
hash_valid(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-17 18:21:44 +00:00
|
|
|
FileRecordData ( std::string&& parPath, uint16_t parRelPathOffs, std::time_t parATime, std::time_t parMTime, uint16_t parLevel, bool parIsDir, bool parIsSymLink ) :
|
2016-03-08 07:48:12 +00:00
|
|
|
hash {},
|
|
|
|
abs_path(std::move(parPath)),
|
|
|
|
mime_full(),
|
|
|
|
atime(parATime),
|
|
|
|
mtime(parMTime),
|
|
|
|
size(0),
|
|
|
|
level(parLevel),
|
2016-05-17 18:21:44 +00:00
|
|
|
path_offset(parRelPathOffs),
|
2016-05-17 19:12:44 +00:00
|
|
|
mime_type_offset(0),
|
|
|
|
mime_type_length(0),
|
|
|
|
mime_charset_offset(0),
|
|
|
|
mime_charset_length(0),
|
2016-03-08 07:48:12 +00:00
|
|
|
is_directory(parIsDir),
|
|
|
|
is_symlink(parIsSymLink),
|
|
|
|
unreadable(false),
|
|
|
|
hash_valid(false)
|
|
|
|
{
|
2016-05-17 18:21:44 +00:00
|
|
|
assert(path_offset <= abs_path.size());
|
2016-03-08 07:48:12 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 17:56:07 +00:00
|
|
|
#if defined(NDEBUG)
|
2015-12-29 17:32:22 +00:00
|
|
|
FileRecordData ( const FileRecordData& ) = delete;
|
2016-02-23 17:56:07 +00:00
|
|
|
#else
|
|
|
|
FileRecordData ( const FileRecordData& ) = default;
|
|
|
|
#endif
|
2015-12-29 17:32:22 +00:00
|
|
|
FileRecordData ( FileRecordData&& ) = default;
|
|
|
|
FileRecordData& operator= ( const FileRecordData& ) = delete;
|
|
|
|
FileRecordData& operator= ( FileRecordData&& ) = default;
|
2016-02-23 17:56:07 +00:00
|
|
|
#if !defined(NDEBUG)
|
|
|
|
bool operator== ( const FileRecordData& parOther ) const;
|
|
|
|
#endif
|
2015-12-29 17:32:22 +00:00
|
|
|
|
2016-05-17 18:21:44 +00:00
|
|
|
boost::string_ref path ( void ) const { return boost::string_ref(abs_path).substr(path_offset); }
|
2016-05-17 19:12:44 +00:00
|
|
|
boost::string_ref mime_type ( void ) const { return boost::string_ref(mime_full.get()).substr(mime_type_offset, mime_type_length); }
|
|
|
|
boost::string_ref mime_charset ( void ) const { return boost::string_ref(mime_full.get()).substr(mime_charset_offset, mime_charset_length); }
|
|
|
|
void set_mime_parts ( boost::string_ref parType, boost::string_ref parCharset ) {
|
|
|
|
const auto& mime = mime_full.get();
|
|
|
|
{
|
2016-05-18 20:25:41 +00:00
|
|
|
assert(std::less_equal<const char*>()(mime.data(), parType.data()));
|
|
|
|
assert(std::less_equal<const char*>()(parType.data() + parType.size(), mime.data() + mime.size()));
|
2016-05-17 19:12:44 +00:00
|
|
|
assert(parType.data() - mime.data() < USHRT_MAX);
|
|
|
|
assert(parType.size() < USHRT_MAX);
|
|
|
|
assert(parType.size() + (parType.data() - mime.data()) <= mime.size());
|
|
|
|
mime_type_offset = static_cast<uint16_t>(parType.data() - mime.data());
|
|
|
|
mime_type_length = static_cast<uint16_t>(parType.size());
|
|
|
|
}
|
|
|
|
{
|
2016-05-18 20:25:41 +00:00
|
|
|
assert(std::less_equal<const char*>()(mime.data(), parCharset.data()));
|
|
|
|
assert(std::less_equal<const char*>()(parCharset.data() + parCharset.size(), mime.data() + mime.size()));
|
2016-05-17 19:12:44 +00:00
|
|
|
assert(parCharset.data() - mime.data() < USHRT_MAX);
|
|
|
|
assert(parCharset.size() < USHRT_MAX);
|
|
|
|
assert(parCharset.size() + (parCharset.data() - mime.data()) <= mime.size());
|
|
|
|
mime_charset_offset = static_cast<uint16_t>(parCharset.data() - mime.data());
|
|
|
|
mime_charset_length = static_cast<uint16_t>(parCharset.size());
|
|
|
|
}
|
|
|
|
}
|
2016-05-17 18:21:44 +00:00
|
|
|
|
2015-12-29 17:32:22 +00:00
|
|
|
TigerHash hash;
|
2016-01-11 12:46:06 +00:00
|
|
|
std::string abs_path;
|
2015-12-29 17:32:22 +00:00
|
|
|
mime_string mime_full;
|
|
|
|
std::time_t atime;
|
|
|
|
std::time_t mtime;
|
|
|
|
uint64_t size;
|
|
|
|
uint16_t level;
|
2016-05-17 18:21:44 +00:00
|
|
|
uint16_t path_offset; //Relative path starting character into abs_path
|
2016-05-17 19:12:44 +00:00
|
|
|
uint16_t mime_type_offset; //Mime type starting character into mime_full
|
|
|
|
uint16_t mime_type_length; //Mime type string length
|
|
|
|
uint16_t mime_charset_offset; //Mime charset starting character into mime_full
|
|
|
|
uint16_t mime_charset_length; //Mime charset string length
|
2015-12-29 17:32:22 +00:00
|
|
|
bool is_directory;
|
|
|
|
bool is_symlink;
|
|
|
|
bool unreadable;
|
|
|
|
bool hash_valid;
|
|
|
|
};
|
|
|
|
|
2016-02-22 18:44:48 +00:00
|
|
|
struct SetRecordData {
|
|
|
|
boost::string_ref name;
|
2015-12-29 17:32:22 +00:00
|
|
|
char type;
|
2016-02-22 18:44:48 +00:00
|
|
|
char content_type;
|
2015-12-29 17:32:22 +00:00
|
|
|
};
|
|
|
|
|
2016-02-22 18:44:48 +00:00
|
|
|
struct SetRecordDataFull : public SetRecordData {
|
|
|
|
std::string name;
|
2016-06-03 23:03:20 +00:00
|
|
|
std::string disk_label;
|
|
|
|
std::string fs_uuid;
|
2016-02-22 18:44:48 +00:00
|
|
|
uint32_t disk_number;
|
2015-12-29 17:32:22 +00:00
|
|
|
};
|
2016-02-23 17:56:07 +00:00
|
|
|
|
|
|
|
#if !defined(NDEBUG)
|
|
|
|
inline bool FileRecordData::operator== (const FileRecordData& parOther) const {
|
|
|
|
return (this->abs_path == parOther.abs_path);
|
|
|
|
}
|
|
|
|
#endif
|
2016-01-05 12:49:27 +00:00
|
|
|
} //namespace mchlib
|
2015-12-29 17:32:22 +00:00
|
|
|
|
|
|
|
#endif
|