1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-08-13 14:39:47 +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

@ -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() {