1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-02-19 12:04:54 +00:00

Add ShortFileRecordData struct to hold the file list in DirTree.

This commit is contained in:
King_DuckZ 2016-03-04 21:57:09 +01:00
parent 1956594c01
commit d579b311f2
6 changed files with 57 additions and 25 deletions

View file

@ -79,6 +79,16 @@ namespace mchlib {
bool hash_valid;
};
struct ShortFileRecordData {
std::string abs_path;
std::string path;
std::time_t atime;
std::time_t mtime;
uint16_t level;
bool is_directory;
bool is_symlink;
};
struct SetRecordData {
boost::string_ref name;
char type;

View file

@ -23,19 +23,19 @@
#include <vector>
namespace mchlib {
struct FileRecordData;
struct ShortFileRecordData;
namespace scantask {
class DirTree : public Base<std::vector<FileRecordData>> {
class DirTree : public Base<std::vector<ShortFileRecordData>> {
public:
typedef std::vector<FileRecordData> PathList;
typedef std::vector<ShortFileRecordData> PathList;
explicit DirTree ( std::string parRoot );
virtual ~DirTree ( void ) noexcept = default;
private:
virtual void on_data_destroy ( PathList& parData );
virtual void on_data_create ( PathList& parData );
virtual void on_data_destroy ( PathList& parData ) override;
virtual void on_data_create ( PathList& parData ) override;
std::string m_root;
};

View file

@ -30,8 +30,8 @@ namespace mchlib {
virtual ~MediaType ( void ) noexcept = default;
private:
virtual void on_data_destroy ( MediaTypes& parData );
virtual void on_data_create ( MediaTypes& parData );
virtual void on_data_destroy ( MediaTypes& parData ) override;
virtual void on_data_create ( MediaTypes& parData ) override;
MediaTypes m_default;
#if defined(WITH_MEDIA_AUTODETECT)

View file

@ -128,6 +128,7 @@ namespace mchlib {
class SetListing {
public:
typedef std::vector<FileRecordData> ListType;
typedef std::vector<ShortFileRecordData> ShortListType;
typedef implem::DirIterator<true> const_iterator;
explicit SetListing ( ListType&& parList, bool parSort=true );
@ -151,6 +152,7 @@ namespace mchlib {
static void sort_list ( ListType& parList );
static ListType::iterator lower_bound ( ListType& parList, const char* parPath, uint16_t parLevel, bool parIsDir );
static ShortListType::iterator lower_bound ( ShortListType& parList, const char* parPath, uint16_t parLevel, bool parIsDir );
private:
ListType m_list;

View file

@ -19,25 +19,18 @@
#include "dindexer-machinery/recorddata.hpp"
#include "dindexer-machinery/set_listing.hpp"
#include "filesearcher.hpp"
#include "pathname.hpp"
#include <utility>
#include <cassert>
#include <ciso646>
#include <functional>
#include <algorithm>
namespace mchlib {
namespace {
FileRecordData make_file_record_data (const char* parPath, const fastf::FileStats& parSt) {
return FileRecordData(
parPath,
parSt.atime,
parSt.mtime,
parSt.level,
parSt.is_dir,
parSt.is_symlink
);
}
bool add_path (scantask::DirTree::PathList& parOut, const PathName& parRoot, const char* parPath, const fastf::FileStats& parStats) {
using boost::string_ref;
bool add_path (scantask::DirTree::PathList& parOut, const char* parPath, const fastf::FileStats& parStats) {
auto it_before = SetListing::lower_bound(
parOut,
parPath,
@ -45,9 +38,25 @@ namespace mchlib {
parStats.is_dir
);
//std::string curr_path(parPath);
//const std::size_t offset = parBase.str_path_size() + 1;
//for (FileRecordData& itm : parItems) {
// const auto curr_offset = std::min(parRelPathOffs, curr_path.size());
// itm.path = boost::string_ref(itm.abs_path).substr(curr_offset);
// assert(itm.path.data());
//}
parOut.insert(
it_before,
make_file_record_data(parPath, parStats)
ShortFileRecordData {
std::string(parPath),
make_relative_path(parRoot, PathName(string_ref(parPath))).path(),
parStats.atime,
parStats.mtime,
static_cast<uint16_t>(parStats.level),
static_cast<bool>(parStats.is_dir),
static_cast<bool>(parStats.is_symlink)
}
);
return true;
}
@ -67,6 +76,7 @@ namespace mchlib {
void DirTree::on_data_create (PathList& parData) {
using std::placeholders::_1;
using std::placeholders::_2;
using boost::string_ref;
assert(parData.empty());
@ -74,7 +84,11 @@ namespace mchlib {
fastf::FileSearcher::ConstCharVecType ext, ignore;
searcher.SetFollowSymlinks(true);
searcher.SetCallback(fastf::FileSearcher::CallbackType(std::bind(&add_path, std::ref(parData), _1, _2)));
searcher.SetCallback(
fastf::FileSearcher::CallbackType(
std::bind(&add_path, std::ref(parData), PathName(string_ref(m_root)), _1, _2)
)
);
searcher.Search(ext, ignore);
}
} //namespace scantask

View file

@ -41,9 +41,9 @@ namespace mchlib {
bool is_directory;
};
template <typename OtherRecord>
bool file_record_data_lt (const FileRecordData& parLeft, const OtherRecord& parRight) {
const FileRecordData& l = parLeft;
template <typename RecordType, typename OtherRecord>
bool file_record_data_lt (const RecordType& parLeft, const OtherRecord& parRight) {
const RecordType& l = parLeft;
const OtherRecord& r = parRight;
return
(l.level < r.level)
@ -279,13 +279,19 @@ namespace mchlib {
}
void SetListing::sort_list (ListType& parList) {
std::sort(parList.begin(), parList.end(), &file_record_data_lt<FileRecordData>);
std::sort(parList.begin(), parList.end(), &file_record_data_lt<FileRecordData, FileRecordData>);
}
SetListing::ListType::iterator SetListing::lower_bound (ListType& parList, const char* parPath, uint16_t parLevel, bool parIsDir) {
using boost::string_ref;
FileRecordDataForSearch find_record(parPath, parLevel, parIsDir);
return std::lower_bound(parList.begin(), parList.end(), find_record, &file_record_data_lt<FileRecordDataForSearch>);
return std::lower_bound(parList.begin(), parList.end(), find_record, &file_record_data_lt<FileRecordData, FileRecordDataForSearch>);
}
SetListing::ShortListType::iterator SetListing::lower_bound (ShortListType& parList, const char* parPath, uint16_t parLevel, bool parIsDir) {
using boost::string_ref;
FileRecordDataForSearch find_record(parPath, parLevel, parIsDir);
return std::lower_bound(parList.begin(), parList.end(), find_record, &file_record_data_lt<ShortFileRecordData, FileRecordDataForSearch>);
}
SetListingView<false> SetListing::make_view() {