1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-07-02 14:04:22 +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; 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 { struct SetRecordData {
boost::string_ref name; boost::string_ref name;
char type; char type;

View file

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

View file

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

View file

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

View file

@ -19,25 +19,18 @@
#include "dindexer-machinery/recorddata.hpp" #include "dindexer-machinery/recorddata.hpp"
#include "dindexer-machinery/set_listing.hpp" #include "dindexer-machinery/set_listing.hpp"
#include "filesearcher.hpp" #include "filesearcher.hpp"
#include "pathname.hpp"
#include <utility> #include <utility>
#include <cassert> #include <cassert>
#include <ciso646> #include <ciso646>
#include <functional> #include <functional>
#include <algorithm>
namespace mchlib { namespace mchlib {
namespace { namespace {
FileRecordData make_file_record_data (const char* parPath, const fastf::FileStats& parSt) { bool add_path (scantask::DirTree::PathList& parOut, const PathName& parRoot, const char* parPath, const fastf::FileStats& parStats) {
return FileRecordData( using boost::string_ref;
parPath,
parSt.atime,
parSt.mtime,
parSt.level,
parSt.is_dir,
parSt.is_symlink
);
}
bool add_path (scantask::DirTree::PathList& parOut, const char* parPath, const fastf::FileStats& parStats) {
auto it_before = SetListing::lower_bound( auto it_before = SetListing::lower_bound(
parOut, parOut,
parPath, parPath,
@ -45,9 +38,25 @@ namespace mchlib {
parStats.is_dir 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( parOut.insert(
it_before, 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; return true;
} }
@ -67,6 +76,7 @@ namespace mchlib {
void DirTree::on_data_create (PathList& parData) { void DirTree::on_data_create (PathList& parData) {
using std::placeholders::_1; using std::placeholders::_1;
using std::placeholders::_2; using std::placeholders::_2;
using boost::string_ref;
assert(parData.empty()); assert(parData.empty());
@ -74,7 +84,11 @@ namespace mchlib {
fastf::FileSearcher::ConstCharVecType ext, ignore; fastf::FileSearcher::ConstCharVecType ext, ignore;
searcher.SetFollowSymlinks(true); 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); searcher.Search(ext, ignore);
} }
} //namespace scantask } //namespace scantask

View file

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