Add FileManager::copy_file_id.

This commit is contained in:
levlam 2023-05-24 15:28:40 +03:00
parent 526b602b61
commit dd7fe47db8
5 changed files with 20 additions and 20 deletions

View File

@ -4806,11 +4806,7 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
auto fix_file_id = [dialog_id, to_secret, file_manager = td->file_manager_.get()](FileId file_id) {
auto file_view = file_manager->get_file_view(file_id);
if (to_secret && !file_view.is_encrypted_secret()) {
auto download_file_id = file_manager->dup_file_id(file_id, "dup_message_content to secret");
file_id = file_manager
->register_generate(FileType::Encrypted, FileLocationSource::FromServer, file_view.suggested_path(),
PSTRING() << "#file_id#" << download_file_id.get(), dialog_id, file_view.size())
.ok();
file_id = file_manager->copy_file_id(file_id, FileType::Encrypted, dialog_id, "copy message content to secret");
}
return file_manager->dup_file_id(file_id, "dup_message_content");
};

View File

@ -949,13 +949,9 @@ void NotificationSettingsManager::add_saved_ringtone(td_api::object_ptr<td_api::
return;
}
auto download_file_id = td_->file_manager_->dup_file_id(file_id, "add_saved_ringtone");
file_id = td_->file_manager_
->register_generate(FileType::Ringtone, FileLocationSource::FromServer, file_view.suggested_path(),
PSTRING() << "#file_id#" << download_file_id.get(), DialogId(), file_view.size())
.ok();
file_id = td_->file_manager_->copy_file_id(file_id, FileType::Ringtone, DialogId(), "add_saved_ringtone");
upload_ringtone(file_id, false, std::move(promise));
upload_ringtone(td_->file_manager_->dup_file_id(file_id, "add_saved_ringtone"), false, std::move(promise));
}
void NotificationSettingsManager::upload_ringtone(FileId file_id, bool is_reupload,

View File

@ -546,12 +546,7 @@ void SetSecureValue::start_upload(FileManager *file_manager, FileId &file_id, Se
bool force = false;
if (info.file_id.empty()) {
if (!file_view.is_encrypted_secure()) {
auto download_file_id = file_manager->dup_file_id(file_id, "SetSecureValue");
file_id =
file_manager
->register_generate(FileType::SecureEncrypted, FileLocationSource::FromServer, file_view.suggested_path(),
PSTRING() << "#file_id#" << download_file_id.get(), DialogId(), file_view.size())
.ok();
file_id = file_manager->copy_file_id(file_id, FileType::SecureEncrypted, DialogId(), "SetSecureValue");
}
info.file_id = file_manager->dup_file_id(file_id, "SetSecureValue");

View File

@ -1102,9 +1102,20 @@ FileId FileManager::dup_file_id(FileId file_id, const char *source) {
if (!file_node) {
return FileId();
}
auto result = FileId(create_file_id(file_node_id, file_node).get(), file_id.get_remote());
LOG(INFO) << "Dup file " << file_id << " to " << result << " from " << source;
return result;
auto result_file_id = FileId(create_file_id(file_node_id, file_node).get(), file_id.get_remote());
LOG(INFO) << "Dup file " << file_id << " to " << result_file_id << " from " << source;
return result_file_id;
}
FileId FileManager::copy_file_id(FileId file_id, FileType file_type, DialogId owner_dialog_id, const char *source) {
auto file_view = get_file_view(file_id);
auto download_file_id = dup_file_id(file_id, source);
auto result_file_id =
register_generate(file_type, FileLocationSource::FromServer, file_view.suggested_path(),
PSTRING() << "#file_id#" << download_file_id.get(), owner_dialog_id, file_view.size())
.ok();
LOG(INFO) << "Copy file " << file_id << " to " << result_file_id << " from " << source;
return result_file_id;
}
FileId FileManager::create_file_id(int32 file_node_id, FileNode *file_node) {

View File

@ -425,6 +425,8 @@ class FileManager final : public FileLoadManager::Callback {
FileId dup_file_id(FileId file_id, const char *source);
FileId copy_file_id(FileId file_id, FileType file_type, DialogId owner_dialog_id, const char *source);
void on_file_unlink(const FullLocalFileLocation &location);
FileId register_empty(FileType type);