diff --git a/src/machinery/indexer.cpp b/src/machinery/indexer.cpp index 001e28d..13627d0 100644 --- a/src/machinery/indexer.cpp +++ b/src/machinery/indexer.cpp @@ -47,12 +47,27 @@ namespace mchlib { namespace { typedef std::vector::iterator FileEntryIt; + void append_to_vec (std::vector& parDest, const HashType& parHash, const std::string& parString) { + const auto old_size = parDest.size(); + parDest.resize(old_size + sizeof(HashType) + parString.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)); + } + + void append_to_vec (std::vector& parDest, const std::string& parString) { + const auto old_size = parDest.size(); + parDest.resize(old_size + parString.size()); + std::copy(parString.begin(), parString.end(), parDest.begin() + old_size); + } + void hash_dir (FileEntryIt parEntry, FileEntryIt parBegin, FileEntryIt parEnd, const PathName& parCurrDir, std::function parNextItemCallback, bool parIgnoreErrors, MimeType& parMime) { assert(parEntry != parEnd); assert(parEntry->is_directory); FileRecordData& curr_entry = *parEntry; auto& curr_entry_it = parEntry; + curr_entry.mime_full = parMime.analyze(curr_entry.abs_path); + //Build a blob with the hashes and filenames of every directory that //is a direct child of current entry { @@ -73,23 +88,17 @@ namespace mchlib { #if defined(INDEXER_VERBOSE) std::cout << "Making initial hash for " << parCurrDir << "...\n"; #endif - curr_entry.mime_full = parMime.analyze(curr_entry.abs_path); while (parEnd != it_entry and it_entry->level == curr_entry_it->level + 1 and parCurrDir == PathName(it_entry->abs_path).pop_right()) { PathName curr_subdir(it_entry->abs_path); + const std::string relpath = make_relative_path(parCurrDir, curr_subdir).path(); + std::cout << "Adding " << relpath << " to blob\n"; + if (it_entry->is_directory) { hash_dir(it_entry, parBegin, parEnd, curr_subdir, parNextItemCallback, parIgnoreErrors, parMime); - - std::string relpath = make_relative_path(parCurrDir, curr_subdir).path(); - const auto old_size = dir_blob.size(); - dir_blob.resize(old_size + sizeof(HashType) + relpath.size()); - std::copy(it_entry->hash.byte_data, it_entry->hash.byte_data + sizeof(HashType), dir_blob.begin() + old_size); - std::copy(relpath.begin(), relpath.end(), dir_blob.begin() + old_size + sizeof(HashType)); + append_to_vec(dir_blob, it_entry->hash, relpath); } else { - std::string relpath = make_relative_path(parCurrDir, curr_subdir).path(); - const auto old_size = dir_blob.size(); - dir_blob.resize(old_size + relpath.size()); - std::copy(relpath.begin(), relpath.end(), dir_blob.begin() + old_size); + append_to_vec(dir_blob, relpath); } ++it_entry; } diff --git a/src/machinery/mimetype.cpp b/src/machinery/mimetype.cpp index 0626f06..73b6afa 100644 --- a/src/machinery/mimetype.cpp +++ b/src/machinery/mimetype.cpp @@ -1,3 +1,20 @@ +/* Copyright 2016, Michele Santullo + * This file is part of "dindexer". + * + * "dindexer" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * "dindexer" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with "dindexer". If not, see . + */ + #include "mimetype.hpp" #include #include diff --git a/src/machinery/mimetype.hpp b/src/machinery/mimetype.hpp index 1528ff1..70ba060 100644 --- a/src/machinery/mimetype.hpp +++ b/src/machinery/mimetype.hpp @@ -1,4 +1,4 @@ -/* Copyright 2015, Michele Santullo +/* Copyright 2016, Michele Santullo * This file is part of "dindexer". * * "dindexer" is free software: you can redistribute it and/or modify