DownloadManager: remove file when local file is removed
This commit is contained in:
parent
6079b1a2b4
commit
f1cf7bdc3f
@ -125,6 +125,23 @@ class DownloadManagerImpl final : public DownloadManager {
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status remove_file_if_finished(FileId file_id) {
|
||||
TRY_STATUS(check_is_active());
|
||||
TRY_RESULT(file_info_ptr, get_file_info(file_id, {}));
|
||||
if (!is_completed(*file_info_ptr)) {
|
||||
return Status::Error("File is active");
|
||||
}
|
||||
return remove_file(file_id, {}, false);
|
||||
}
|
||||
|
||||
Status change_search_text(FileId file_id, FileSourceId file_source_id, string search_text) final {
|
||||
TRY_STATUS(check_is_active());
|
||||
TRY_RESULT(file_info_ptr, get_file_info(file_id, file_source_id));
|
||||
auto &file_info = *file_info_ptr;
|
||||
hints_.add(file_info.download_id, search_text.empty() ? string(" ") : search_text);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status remove_all_files(bool only_active, bool only_completed, bool delete_from_cache) final {
|
||||
TRY_STATUS(check_is_active());
|
||||
vector<FileId> to_remove;
|
||||
@ -165,18 +182,6 @@ class DownloadManagerImpl final : public DownloadManager {
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status change_search_text(FileId file_id, FileSourceId file_source_id, string search_text) final {
|
||||
if (!is_search_inited_) {
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
TRY_STATUS(check_is_active());
|
||||
TRY_RESULT(file_info_ptr, get_file_info(file_id, file_source_id));
|
||||
auto &file_info = *file_info_ptr;
|
||||
hints_.add(file_info.download_id, search_text.empty() ? string(" ") : search_text);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
void hints_synchronized(Result<Unit>) {
|
||||
if (G()->close_flag()) {
|
||||
return;
|
||||
|
@ -71,6 +71,7 @@ class DownloadManager : public Actor {
|
||||
virtual void search(string query, bool only_active, bool only_completed, string offset, int32 limit,
|
||||
Promise<td_api::object_ptr<td_api::foundFileDownloads>> promise) = 0;
|
||||
virtual Status remove_file(FileId file_id, FileSourceId file_source_id, bool delete_from_cache) = 0;
|
||||
virtual Status remove_file_if_finished(FileId file_id) = 0;
|
||||
virtual Status remove_all_files(bool only_active, bool only_completed, bool delete_from_cache) = 0;
|
||||
|
||||
//
|
||||
|
@ -36,6 +36,7 @@ class ConfigManager;
|
||||
class ConfigShared;
|
||||
class ConnectionCreator;
|
||||
class ContactsManager;
|
||||
class DownloadManager;
|
||||
class FileManager;
|
||||
class FileReferenceManager;
|
||||
class GameManager;
|
||||
@ -205,6 +206,13 @@ class Global final : public ActorContext {
|
||||
contacts_manager_ = contacts_manager;
|
||||
}
|
||||
|
||||
ActorId<DownloadManager> download_manager() const {
|
||||
return download_manager_;
|
||||
}
|
||||
void set_download_manager(ActorId<DownloadManager> download_manager) {
|
||||
download_manager_ = std::move(download_manager);
|
||||
}
|
||||
|
||||
ActorId<FileManager> file_manager() const {
|
||||
return file_manager_;
|
||||
}
|
||||
@ -437,6 +445,7 @@ class Global final : public ActorContext {
|
||||
ActorId<CallManager> call_manager_;
|
||||
ActorId<ConfigManager> config_manager_;
|
||||
ActorId<ContactsManager> contacts_manager_;
|
||||
ActorId<DownloadManager> download_manager_;
|
||||
ActorId<FileManager> file_manager_;
|
||||
ActorId<FileReferenceManager> file_reference_manager_;
|
||||
ActorId<GameManager> game_manager_;
|
||||
|
@ -3973,6 +3973,7 @@ void Td::init_managers() {
|
||||
country_info_manager_actor_ = register_actor("CountryInfoManager", country_info_manager_.get());
|
||||
download_manager_ = DownloadManager::create(td::make_unique<DownloadManagerCallback>(this, create_reference()));
|
||||
download_manager_actor_ = register_actor("DownloadManager", download_manager_.get());
|
||||
G()->set_download_manager(download_manager_actor_.get());
|
||||
game_manager_ = make_unique<GameManager>(this, create_reference());
|
||||
game_manager_actor_ = register_actor("GameManager", game_manager_.get());
|
||||
G()->set_game_manager(game_manager_actor_.get());
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "td/telegram/files/FileManager.h"
|
||||
|
||||
#include "td/telegram/ConfigShared.h"
|
||||
#include "td/telegram/DownloadManager.h"
|
||||
#include "td/telegram/FileReferenceManager.h"
|
||||
#include "td/telegram/files/FileData.h"
|
||||
#include "td/telegram/files/FileDb.h"
|
||||
@ -1028,6 +1029,7 @@ Status FileManager::check_local_location(FileNodePtr node) {
|
||||
status = check_partial_local_location(node->local_.partial());
|
||||
}
|
||||
if (status.is_error()) {
|
||||
send_closure(G()->download_manager(), &DownloadManager::remove_file_if_finished, node->main_file_id_);
|
||||
node->drop_local_location();
|
||||
try_flush_node(node, "check_local_location");
|
||||
}
|
||||
@ -1118,6 +1120,7 @@ void FileManager::on_file_unlink(const FullLocalFileLocation &location) {
|
||||
auto file_id = it->second;
|
||||
auto file_node = get_sync_file_node(file_id);
|
||||
CHECK(file_node);
|
||||
send_closure(G()->download_manager(), &DownloadManager::remove_file, file_node->main_file_id_, FileSourceId{}, false);
|
||||
file_node->drop_local_location();
|
||||
try_flush_node_info(file_node, "on_file_unlink");
|
||||
}
|
||||
@ -2143,6 +2146,7 @@ void FileManager::delete_file(FileId file_id, Promise<Unit> promise, const char
|
||||
|
||||
auto file_view = FileView(node);
|
||||
|
||||
send_closure(G()->download_manager(), &DownloadManager::remove_file, file_view.file_id(), FileSourceId{}, false);
|
||||
// TODO review delete condition
|
||||
if (file_view.has_local_location()) {
|
||||
if (begins_with(file_view.local_location().path_, get_files_dir(file_view.get_type()))) {
|
||||
|
Loading…
Reference in New Issue
Block a user