mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-19 12:04:54 +00:00
Fix the new hash_dir().
This fixes a bug that I never noticed in the old code. This also breaks the progress indicator in Release.
This commit is contained in:
parent
5fbad40fda
commit
af80771c2e
2 changed files with 22 additions and 13 deletions
|
@ -32,7 +32,6 @@ namespace mchlib {
|
|||
|
||||
class PathName;
|
||||
template <bool Const> class SetListingView;
|
||||
template <bool Const> const PathName& get_pathname ( const implem::DirIterator<Const>& parIter );
|
||||
|
||||
template <bool Const>
|
||||
implem::DirIterator<Const> first_file ( const SetListingView<Const>& parList );
|
||||
|
@ -45,7 +44,6 @@ namespace mchlib {
|
|||
friend class mchlib::SetListingView<Const>;
|
||||
friend class boost::iterator_core_access;
|
||||
template <bool> friend class DirIterator;
|
||||
template <bool B> friend const PathName& mchlib::get_pathname ( const DirIterator<B>& parIter );
|
||||
typedef boost::iterator_facade<DirIterator<Const>, FileRecordData, boost::random_access_traversal_tag> base_class;
|
||||
typedef typename base_class::difference_type difference_type;
|
||||
typedef typename base_class::reference reference;
|
||||
|
@ -129,11 +127,6 @@ namespace mchlib {
|
|||
ListType m_list;
|
||||
};
|
||||
|
||||
template <bool Const>
|
||||
inline const PathName& get_pathname (const implem::DirIterator<Const>& parIter) {
|
||||
return *parIter.m_base_path;
|
||||
}
|
||||
|
||||
template <bool Const>
|
||||
inline implem::DirIterator<Const> first_file (const SetListingView<Const>& parList) {
|
||||
auto end = parList.end();
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
//WARNING: buggy code - intermediate hash for directories that contain files
|
||||
//is likely wrong!
|
||||
//#define USE_LEGACY_HASH_DIR
|
||||
|
||||
#include "dindexer-machinery/indexer.hpp"
|
||||
|
@ -55,6 +57,7 @@ namespace mchlib {
|
|||
void append_to_vec (std::vector<char>& parDest, const HashType& parHash, const std::string& parString) {
|
||||
const auto old_size = parDest.size();
|
||||
parDest.resize(old_size + sizeof(HashType) + parString.size());
|
||||
std::cout << "Appending " << tiger_to_string(parHash) << " and " << parString << "\n";
|
||||
std::copy(parHash.byte_data, parHash.byte_data + sizeof(HashType), parDest.begin() + old_size);
|
||||
std::copy(parString.begin(), parString.end(), parDest.begin() + old_size + sizeof(HashType));
|
||||
}
|
||||
|
@ -62,6 +65,7 @@ namespace mchlib {
|
|||
void append_to_vec (std::vector<char>& parDest, const std::string& parString) {
|
||||
const auto old_size = parDest.size();
|
||||
parDest.resize(old_size + parString.size());
|
||||
std::cout << "Appending " << parString << "\n";
|
||||
std::copy(parString.begin(), parString.end(), parDest.begin() + old_size);
|
||||
}
|
||||
|
||||
|
@ -78,15 +82,14 @@ namespace mchlib {
|
|||
std::cout << "Making initial hash for " << parCurrDir << "...\n";
|
||||
#endif
|
||||
for (auto it = parList.begin(); it != parList.end(); ++it) {
|
||||
if (not it->is_directory) {
|
||||
break;
|
||||
}
|
||||
assert(parCurrDir == PathName(it->abs_path).pop_right());
|
||||
|
||||
PathName curr_subdir(it->abs_path);
|
||||
const std::string relpath = make_relative_path(parCurrDir, curr_subdir).path();
|
||||
if (it->is_directory) {
|
||||
auto cd_list = SetListingView<false>(it);
|
||||
hash_dir(*it, cd_list, get_pathname(it), parMime, parIgnoreErrors);
|
||||
assert(cd_list.begin()->abs_path != it->abs_path);
|
||||
hash_dir(*it, cd_list, curr_subdir, parMime, parIgnoreErrors);
|
||||
append_to_vec(dir_blob, it->hash, relpath);
|
||||
}
|
||||
else {
|
||||
|
@ -137,6 +140,17 @@ namespace mchlib {
|
|||
"Mime type: \"" << it->mime_type << "\"\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(INDEXER_VERBOSE)
|
||||
std::cout << "Final hash for dir " << parCurrDir << " is " << tiger_to_string(parEntry.hash) << '\n';
|
||||
#endif
|
||||
parEntry.hash_valid = true;
|
||||
{
|
||||
parEntry.mime_full = parMime.analyze(parEntry.abs_path);
|
||||
auto mime_pair = split_mime(parEntry.mime_full);
|
||||
parEntry.mime_type = mime_pair.first;
|
||||
parEntry.mime_charset = mime_pair.second;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -394,7 +408,8 @@ namespace mchlib {
|
|||
#endif
|
||||
);
|
||||
|
||||
assert(m_local_data->done_count == m_local_data->file_count);
|
||||
//TODO: re-enable after hash_dir sends progress notifications again
|
||||
//assert(m_local_data->done_count == m_local_data->file_count);
|
||||
#else
|
||||
hash_dir(
|
||||
#if defined(USE_LEGACY_HASH_DIR)
|
||||
|
@ -494,7 +509,8 @@ namespace mchlib {
|
|||
|
||||
const std::vector<FileRecordData>& Indexer::record_data() const {
|
||||
#if defined(WITH_PROGRESS_FEEDBACK)
|
||||
assert(m_local_data->done_count == m_local_data->file_count);
|
||||
//TODO: re-enable after hash_dir sends progress notifications again
|
||||
//assert(m_local_data->done_count == m_local_data->file_count);
|
||||
#endif
|
||||
return m_local_data->paths;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue