mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-07-03 14:14:11 +00:00
Add level offset.
The level in the FileRecordData is 0 at the base of the directory being scanned. However PathName::atom_count() can be more than that. For example scanning /mnt/cdrom will have level 0 at the mount point, but atom_count() is 2. So it's necessary to pass in this offset. This way the code can take that into account and compute stuff correctly.
This commit is contained in:
parent
5908828390
commit
5fbad40fda
3 changed files with 34 additions and 23 deletions
|
@ -60,7 +60,7 @@ namespace mchlib {
|
||||||
DirIterator ( DirIterator<Const>&& parOther );
|
DirIterator ( DirIterator<Const>&& parOther );
|
||||||
template <bool OtherConst>
|
template <bool OtherConst>
|
||||||
DirIterator ( DirIterator<OtherConst>&& parOther, typename std::enable_if<std::is_convertible<typename DirIterator<OtherConst>::VecIterator, VecIterator>::value, enabler>::type = enabler() );
|
DirIterator ( DirIterator<OtherConst>&& parOther, typename std::enable_if<std::is_convertible<typename DirIterator<OtherConst>::VecIterator, VecIterator>::value, enabler>::type = enabler() );
|
||||||
DirIterator ( VecIterator parBegin, VecIterator parEnd, std::unique_ptr<PathName>&& parBasePath );
|
DirIterator ( VecIterator parBegin, VecIterator parEnd, std::unique_ptr<PathName>&& parBasePath, std::size_t parLevelOffset );
|
||||||
~DirIterator ( void ) noexcept;
|
~DirIterator ( void ) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -75,6 +75,7 @@ namespace mchlib {
|
||||||
VecIterator m_current;
|
VecIterator m_current;
|
||||||
VecIterator m_end;
|
VecIterator m_end;
|
||||||
std::unique_ptr<PathName> m_base_path;
|
std::unique_ptr<PathName> m_base_path;
|
||||||
|
std::size_t m_level_offset;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -87,7 +88,7 @@ namespace mchlib {
|
||||||
typedef typename implem::DirIterator<Const>::VecIterator list_iterator;
|
typedef typename implem::DirIterator<Const>::VecIterator list_iterator;
|
||||||
|
|
||||||
explicit SetListingView ( const implem::DirIterator<Const>& parIter );
|
explicit SetListingView ( const implem::DirIterator<Const>& parIter );
|
||||||
SetListingView ( list_iterator parBeg, list_iterator parEnd );
|
SetListingView ( list_iterator parBeg, list_iterator parEnd, std::size_t parLevelOffset );
|
||||||
SetListingView ( SetListingView&& ) = default;
|
SetListingView ( SetListingView&& ) = default;
|
||||||
~SetListingView ( void ) noexcept = default;
|
~SetListingView ( void ) noexcept = default;
|
||||||
|
|
||||||
|
@ -103,6 +104,7 @@ namespace mchlib {
|
||||||
private:
|
private:
|
||||||
list_iterator m_begin;
|
list_iterator m_begin;
|
||||||
list_iterator m_end;
|
list_iterator m_end;
|
||||||
|
std::size_t m_level_offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SetListing {
|
class SetListing {
|
||||||
|
|
|
@ -368,7 +368,7 @@ namespace mchlib {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(USE_LEGACY_HASH_DIR)
|
#if !defined(USE_LEGACY_HASH_DIR)
|
||||||
SetListingView<false> recordlist(m_local_data->paths.begin(), m_local_data->paths.end());
|
SetListingView<false> recordlist(m_local_data->paths.begin(), m_local_data->paths.end(), base_path.atom_count());
|
||||||
#endif
|
#endif
|
||||||
#if defined(WITH_PROGRESS_FEEDBACK)
|
#if defined(WITH_PROGRESS_FEEDBACK)
|
||||||
m_local_data->done_count = 0;
|
m_local_data->done_count = 0;
|
||||||
|
|
|
@ -49,7 +49,8 @@ namespace mchlib {
|
||||||
DirIterator<Const>::DirIterator (DirIterator<Const>&& parOther) :
|
DirIterator<Const>::DirIterator (DirIterator<Const>&& parOther) :
|
||||||
m_current(std::move(parOther.m_current)),
|
m_current(std::move(parOther.m_current)),
|
||||||
m_end(std::move(parOther.m_end)),
|
m_end(std::move(parOther.m_end)),
|
||||||
m_base_path(std::move(parOther.m_base_path))
|
m_base_path(std::move(parOther.m_base_path)),
|
||||||
|
m_level_offset(parOther.m_level_offset)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,23 +59,26 @@ namespace mchlib {
|
||||||
DirIterator<Const>::DirIterator (DirIterator<OtherConst>&& parOther, typename std::enable_if<std::is_convertible<typename DirIterator<OtherConst>::VecIterator, VecIterator>::value, enabler>::type) :
|
DirIterator<Const>::DirIterator (DirIterator<OtherConst>&& parOther, typename std::enable_if<std::is_convertible<typename DirIterator<OtherConst>::VecIterator, VecIterator>::value, enabler>::type) :
|
||||||
m_current(parOther.m_current),
|
m_current(parOther.m_current),
|
||||||
m_end(parOther.m_end),
|
m_end(parOther.m_end),
|
||||||
m_base_path(std::move(parOther.m_base_path))
|
m_base_path(std::move(parOther.m_base_path)),
|
||||||
|
m_level_offset(parOther.m_level_offset)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template <bool Const>
|
template <bool Const>
|
||||||
DirIterator<Const>::DirIterator (VecIterator parBegin, VecIterator parEnd, std::unique_ptr<PathName>&& parBasePath) :
|
DirIterator<Const>::DirIterator (VecIterator parBegin, VecIterator parEnd, std::unique_ptr<PathName>&& parBasePath, std::size_t parLevelOffset) :
|
||||||
m_current(parBegin),
|
m_current(parBegin),
|
||||||
m_end(parEnd),
|
m_end(parEnd),
|
||||||
m_base_path(std::move(parBasePath))
|
m_base_path(std::move(parBasePath)),
|
||||||
|
m_level_offset(parLevelOffset)
|
||||||
{
|
{
|
||||||
assert(m_base_path or m_current == m_end);
|
assert(m_base_path or m_current == m_end);
|
||||||
assert(m_current == m_end or m_base_path->atom_count() == m_current->level);
|
assert(m_current == m_end or m_base_path->atom_count() == PathName(m_current->abs_path).atom_count());
|
||||||
|
assert(m_current == m_end or m_base_path->atom_count() == m_current->level + m_level_offset);
|
||||||
|
|
||||||
//Look for the point where the children of this entry starts
|
//Look for the point where the children of this entry starts
|
||||||
while (
|
while (
|
||||||
m_current != m_end and (
|
m_current != m_end and (
|
||||||
m_current->level == m_base_path->atom_count() or
|
m_current->level + m_level_offset == m_base_path->atom_count() or
|
||||||
*m_base_path != PathName(m_current->abs_path).pop_right()
|
*m_base_path != PathName(m_current->abs_path).pop_right()
|
||||||
)) {
|
)) {
|
||||||
assert(m_base_path);
|
assert(m_base_path);
|
||||||
|
@ -93,7 +97,7 @@ namespace mchlib {
|
||||||
++m_current;
|
++m_current;
|
||||||
} while(
|
} while(
|
||||||
m_current != m_end and
|
m_current != m_end and
|
||||||
m_current->level == m_base_path->atom_count() + 1 and
|
m_current->level + m_level_offset == m_base_path->atom_count() + 1 and
|
||||||
*m_base_path != PathName(m_current->abs_path).pop_right()
|
*m_base_path != PathName(m_current->abs_path).pop_right()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -126,7 +130,7 @@ namespace mchlib {
|
||||||
const bool is_this_end =
|
const bool is_this_end =
|
||||||
not m_base_path or
|
not m_base_path or
|
||||||
(m_current == m_end) or
|
(m_current == m_end) or
|
||||||
(m_current->level != m_base_path->atom_count() + 1) /*or
|
(m_current->level + m_level_offset != m_base_path->atom_count() + 1) /*or
|
||||||
(*m_base_path != PathName(m_current->abs_path).pop_right())
|
(*m_base_path != PathName(m_current->abs_path).pop_right())
|
||||||
*/;
|
*/;
|
||||||
return is_this_end;
|
return is_this_end;
|
||||||
|
@ -161,7 +165,7 @@ namespace mchlib {
|
||||||
if (m_list.begin() != m_list.end()) {
|
if (m_list.begin() != m_list.end()) {
|
||||||
base_path.reset(new PathName(m_list.front().abs_path));
|
base_path.reset(new PathName(m_list.front().abs_path));
|
||||||
}
|
}
|
||||||
return const_iterator(m_list.begin(), m_list.end(), std::move(base_path));
|
return const_iterator(m_list.begin(), m_list.end(), std::move(base_path), base_path->atom_count());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto SetListing::end() const -> const_iterator {
|
auto SetListing::end() const -> const_iterator {
|
||||||
|
@ -169,32 +173,37 @@ namespace mchlib {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto SetListing::cend() const -> const_iterator {
|
auto SetListing::cend() const -> const_iterator {
|
||||||
return const_iterator(m_list.end(), m_list.end(), std::unique_ptr<PathName>());
|
return const_iterator(m_list.end(), m_list.end(), std::unique_ptr<PathName>(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetListingView<false> SetListing::make_view() {
|
SetListingView<false> SetListing::make_view() {
|
||||||
return SetListingView<false>(m_list.begin(), m_list.end());
|
const auto offs = (m_list.empty() ? 0 : PathName(m_list.front().abs_path).atom_count());
|
||||||
|
return SetListingView<false>(m_list.begin(), m_list.end(), offs);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetListingView<true> SetListing::make_view() const {
|
SetListingView<true> SetListing::make_view() const {
|
||||||
return SetListingView<true>(m_list.begin(), m_list.end());
|
const auto offs = (m_list.empty() ? 0 : PathName(m_list.front().abs_path).atom_count());
|
||||||
|
return SetListingView<true>(m_list.begin(), m_list.end(), offs);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetListingView<true> SetListing::make_cview() const {
|
SetListingView<true> SetListing::make_cview() const {
|
||||||
return SetListingView<true>(m_list.begin(), m_list.end());
|
const auto offs = (m_list.empty() ? 0 : PathName(m_list.front().abs_path).atom_count());
|
||||||
|
return SetListingView<true>(m_list.begin(), m_list.end(), offs);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <bool Const>
|
template <bool Const>
|
||||||
SetListingView<Const>::SetListingView (const implem::DirIterator<Const>& parIter) :
|
SetListingView<Const>::SetListingView (const implem::DirIterator<Const>& parIter) :
|
||||||
m_begin(parIter.m_current),
|
m_begin(parIter.m_current),
|
||||||
m_end(parIter.m_end)
|
m_end(parIter.m_end),
|
||||||
|
m_level_offset(parIter.m_level_offset)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template <bool Const>
|
template <bool Const>
|
||||||
SetListingView<Const>::SetListingView (list_iterator parBeg, list_iterator parEnd) :
|
SetListingView<Const>::SetListingView (list_iterator parBeg, list_iterator parEnd, std::size_t parLevelOffset) :
|
||||||
m_begin(std::move(parBeg)),
|
m_begin(std::move(parBeg)),
|
||||||
m_end(std::move(parEnd))
|
m_end(std::move(parEnd)),
|
||||||
|
m_level_offset(parLevelOffset)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +218,7 @@ namespace mchlib {
|
||||||
if (m_begin != m_end) {
|
if (m_begin != m_end) {
|
||||||
base_path.reset(new PathName(m_begin->abs_path));
|
base_path.reset(new PathName(m_begin->abs_path));
|
||||||
}
|
}
|
||||||
return const_iterator(m_begin, m_end, std::move(base_path));
|
return const_iterator(m_begin, m_end, std::move(base_path), m_level_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <bool Const>
|
template <bool Const>
|
||||||
|
@ -219,7 +228,7 @@ namespace mchlib {
|
||||||
|
|
||||||
template <bool Const>
|
template <bool Const>
|
||||||
auto SetListingView<Const>::cend() const -> const_iterator {
|
auto SetListingView<Const>::cend() const -> const_iterator {
|
||||||
return const_iterator(m_end, m_end, std::unique_ptr<PathName>());
|
return const_iterator(m_end, m_end, std::unique_ptr<PathName>(), m_level_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <bool Const>
|
template <bool Const>
|
||||||
|
@ -229,13 +238,13 @@ namespace mchlib {
|
||||||
if (m_begin != m_end) {
|
if (m_begin != m_end) {
|
||||||
base_path.reset(new PathName(m_begin->abs_path));
|
base_path.reset(new PathName(m_begin->abs_path));
|
||||||
}
|
}
|
||||||
return iterator(m_begin, m_end, std::move(base_path));
|
return iterator(m_begin, m_end, std::move(base_path), m_level_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <bool Const>
|
template <bool Const>
|
||||||
template <bool B, typename R>
|
template <bool B, typename R>
|
||||||
R SetListingView<Const>::end() {
|
R SetListingView<Const>::end() {
|
||||||
return iterator(m_end, m_end, std::unique_ptr<PathName>());
|
return iterator(m_end, m_end, std::unique_ptr<PathName>(), m_level_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
template class SetListingView<true>;
|
template class SetListingView<true>;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue