Check that FileInfo is in correct state before (un)?register.
This commit is contained in:
parent
044fdb310f
commit
5f8f41b7d6
@ -350,6 +350,7 @@ class DownloadManagerImpl final : public DownloadManager {
|
|||||||
int8 priority;
|
int8 priority;
|
||||||
bool is_paused{};
|
bool is_paused{};
|
||||||
bool is_counted{};
|
bool is_counted{};
|
||||||
|
mutable bool is_registered{};
|
||||||
mutable bool need_save_to_database{};
|
mutable bool need_save_to_database{};
|
||||||
int64 size{};
|
int64 size{};
|
||||||
int64 expected_size{};
|
int64 expected_size{};
|
||||||
@ -680,6 +681,8 @@ class DownloadManagerImpl final : public DownloadManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void unregister_file_info(const FileInfo &file_info) {
|
void unregister_file_info(const FileInfo &file_info) {
|
||||||
|
CHECK(file_info.is_registered);
|
||||||
|
file_info.is_registered = false;
|
||||||
if (file_info.is_counted && (is_completed(file_info) || !file_info.is_paused)) {
|
if (file_info.is_counted && (is_completed(file_info) || !file_info.is_paused)) {
|
||||||
LOG(INFO) << "Unregister file " << file_info.file_id;
|
LOG(INFO) << "Unregister file " << file_info.file_id;
|
||||||
counters_.downloaded_size -= file_info.downloaded_size;
|
counters_.downloaded_size -= file_info.downloaded_size;
|
||||||
@ -689,6 +692,8 @@ class DownloadManagerImpl final : public DownloadManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void register_file_info(FileInfo &file_info) {
|
void register_file_info(FileInfo &file_info) {
|
||||||
|
CHECK(!file_info.is_registered);
|
||||||
|
file_info.is_registered = true;
|
||||||
if (!is_completed(file_info) && file_info.size != 0 && file_info.downloaded_size == file_info.size) {
|
if (!is_completed(file_info) && file_info.size != 0 && file_info.downloaded_size == file_info.size) {
|
||||||
LOG(INFO) << "Register file " << file_info.file_id;
|
LOG(INFO) << "Register file " << file_info.file_id;
|
||||||
file_info.is_paused = false;
|
file_info.is_paused = false;
|
||||||
@ -712,6 +717,7 @@ class DownloadManagerImpl final : public DownloadManager {
|
|||||||
}
|
}
|
||||||
sync_with_database(file_info);
|
sync_with_database(file_info);
|
||||||
update_counters();
|
update_counters();
|
||||||
|
CHECK(file_info.is_registered);
|
||||||
|
|
||||||
check_completed_downloads_size();
|
check_completed_downloads_size();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user