1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-07-03 14:14:11 +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:
King_DuckZ 2016-02-16 23:01:42 +00:00
parent 5fbad40fda
commit af80771c2e
2 changed files with 22 additions and 13 deletions

View file

@ -32,7 +32,6 @@ namespace mchlib {
class PathName; class PathName;
template <bool Const> class SetListingView; template <bool Const> class SetListingView;
template <bool Const> const PathName& get_pathname ( const implem::DirIterator<Const>& parIter );
template <bool Const> template <bool Const>
implem::DirIterator<Const> first_file ( const SetListingView<Const>& parList ); implem::DirIterator<Const> first_file ( const SetListingView<Const>& parList );
@ -45,7 +44,6 @@ namespace mchlib {
friend class mchlib::SetListingView<Const>; friend class mchlib::SetListingView<Const>;
friend class boost::iterator_core_access; friend class boost::iterator_core_access;
template <bool> friend class DirIterator; 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 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::difference_type difference_type;
typedef typename base_class::reference reference; typedef typename base_class::reference reference;
@ -129,11 +127,6 @@ namespace mchlib {
ListType m_list; ListType m_list;
}; };
template <bool Const>
inline const PathName& get_pathname (const implem::DirIterator<Const>& parIter) {
return *parIter.m_base_path;
}
template <bool Const> template <bool Const>
inline implem::DirIterator<Const> first_file (const SetListingView<Const>& parList) { inline implem::DirIterator<Const> first_file (const SetListingView<Const>& parList) {
auto end = parList.end(); auto end = parList.end();

View file

@ -15,6 +15,8 @@
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>. * 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 //#define USE_LEGACY_HASH_DIR
#include "dindexer-machinery/indexer.hpp" #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) { void append_to_vec (std::vector<char>& parDest, const HashType& parHash, const std::string& parString) {
const auto old_size = parDest.size(); const auto old_size = parDest.size();
parDest.resize(old_size + sizeof(HashType) + parString.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(parHash.byte_data, parHash.byte_data + sizeof(HashType), parDest.begin() + old_size);
std::copy(parString.begin(), parString.end(), parDest.begin() + old_size + sizeof(HashType)); 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) { void append_to_vec (std::vector<char>& parDest, const std::string& parString) {
const auto old_size = parDest.size(); const auto old_size = parDest.size();
parDest.resize(old_size + parString.size()); parDest.resize(old_size + parString.size());
std::cout << "Appending " << parString << "\n";
std::copy(parString.begin(), parString.end(), parDest.begin() + old_size); std::copy(parString.begin(), parString.end(), parDest.begin() + old_size);
} }
@ -78,15 +82,14 @@ namespace mchlib {
std::cout << "Making initial hash for " << parCurrDir << "...\n"; std::cout << "Making initial hash for " << parCurrDir << "...\n";
#endif #endif
for (auto it = parList.begin(); it != parList.end(); ++it) { for (auto it = parList.begin(); it != parList.end(); ++it) {
if (not it->is_directory) { assert(parCurrDir == PathName(it->abs_path).pop_right());
break;
}
PathName curr_subdir(it->abs_path); PathName curr_subdir(it->abs_path);
const std::string relpath = make_relative_path(parCurrDir, curr_subdir).path(); const std::string relpath = make_relative_path(parCurrDir, curr_subdir).path();
if (it->is_directory) { if (it->is_directory) {
auto cd_list = SetListingView<false>(it); 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); append_to_vec(dir_blob, it->hash, relpath);
} }
else { else {
@ -137,6 +140,17 @@ namespace mchlib {
"Mime type: \"" << it->mime_type << "\"\n"; "Mime type: \"" << it->mime_type << "\"\n";
#endif #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 #endif
@ -394,7 +408,8 @@ namespace mchlib {
#endif #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 #else
hash_dir( hash_dir(
#if defined(USE_LEGACY_HASH_DIR) #if defined(USE_LEGACY_HASH_DIR)
@ -494,7 +509,8 @@ namespace mchlib {
const std::vector<FileRecordData>& Indexer::record_data() const { const std::vector<FileRecordData>& Indexer::record_data() const {
#if defined(WITH_PROGRESS_FEEDBACK) #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 #endif
return m_local_data->paths; return m_local_data->paths;
} }