Update FileManager.cpp

This commit is contained in:
Andrea Cavalli 2020-08-03 14:26:26 +02:00
parent 159ec55ecf
commit 54531202a8

View File

@ -3841,7 +3841,6 @@ void FileManager::memory_cleanup() {
std::vector<int32> file_to_be_deleted = {}; std::vector<int32> file_to_be_deleted = {};
while (it != file_id_info_.end()) { while (it != file_id_info_.end()) {
if (it->second.node_id_ != 0) {
auto find_node = file_nodes_.find(it->second.node_id_); auto find_node = file_nodes_.find(it->second.node_id_);
if (find_node != file_nodes_.end()) { if (find_node != file_nodes_.end()) {
auto &node = find_node->second; auto &node = find_node->second;
@ -3892,10 +3891,6 @@ void FileManager::memory_cleanup() {
/* The file has a nonexistent node associated */ /* The file has a nonexistent node associated */
file_to_be_deleted.push_back(it->first); file_to_be_deleted.push_back(it->first);
} }
} else {
// todo: When the program starts there is a file that points to the node 0. It shouldn't happen but it happens, so don't delete it, maybe that file is used by tdlib for some reason.
// file_to_be_deleted.push_back(it->first);
}
it++; it++;
} }
@ -3944,7 +3939,9 @@ void FileManager::memory_cleanup() {
if (it->second->main_file_id_.empty()) { if (it->second->main_file_id_.empty()) {
is_invalid = true; is_invalid = true;
} else { } else {
if (file_id_info_[it->second->main_file_id_.get()].node_id_ == 0) { auto find_file_id_info = file_id_info_.find(it->second->main_file_id_.get());
if (find_file_id_info != file_id_info_.end()) {
if (find_file_id_info->second.node_id_ == 0) {
for (auto &file_id : it->second->file_ids_) { for (auto &file_id : it->second->file_ids_) {
context_->destroy_file_source(file_id); context_->destroy_file_source(file_id);
file_id_info_.erase(file_id.get()); file_id_info_.erase(file_id.get());
@ -3952,6 +3949,10 @@ void FileManager::memory_cleanup() {
file_id_info_.erase(it->second->main_file_id_.get()); file_id_info_.erase(it->second->main_file_id_.get());
is_invalid = true; is_invalid = true;
} }
} else {
// todo: is it invalid or not here?
is_invalid = true;
}
} }
} }