Add source to dup_file_id.

This commit is contained in:
levlam 2022-11-21 11:40:43 +03:00
parent ef71f55ec1
commit 0b387a61ad
18 changed files with 40 additions and 34 deletions

View File

@ -255,9 +255,9 @@ FileId AnimationsManager::dup_animation(FileId new_id, FileId old_id) {
CHECK(new_animation == nullptr);
new_animation = make_unique<Animation>(*old_animation);
new_animation->file_id = new_id;
new_animation->thumbnail.file_id = td_->file_manager_->dup_file_id(new_animation->thumbnail.file_id);
new_animation->thumbnail.file_id = td_->file_manager_->dup_file_id(new_animation->thumbnail.file_id, "dup_animation");
new_animation->animated_thumbnail.file_id =
td_->file_manager_->dup_file_id(new_animation->animated_thumbnail.file_id);
td_->file_manager_->dup_file_id(new_animation->animated_thumbnail.file_id, "dup_animation");
return new_id;
}

View File

@ -144,7 +144,7 @@ FileId AudiosManager::dup_audio(FileId new_id, FileId old_id) {
CHECK(new_audio == nullptr);
new_audio = make_unique<Audio>(*old_audio);
new_audio->file_id = new_id;
new_audio->thumbnail.file_id = td_->file_manager_->dup_file_id(new_audio->thumbnail.file_id);
new_audio->thumbnail.file_id = td_->file_manager_->dup_file_id(new_audio->thumbnail.file_id, "dup_audio");
return new_id;
}

View File

@ -781,7 +781,7 @@ void BackgroundManager::save_local_backgrounds(bool for_dark_theme) {
void BackgroundManager::upload_background_file(FileId file_id, const BackgroundType &type, bool for_dark_theme,
Promise<td_api::object_ptr<td_api::background>> &&promise) {
auto upload_file_id = td_->file_manager_->dup_file_id(file_id);
auto upload_file_id = td_->file_manager_->dup_file_id(file_id, "upload_background_file");
bool is_inserted =
being_uploaded_files_.emplace(upload_file_id, UploadedFileInfo(type, for_dark_theme, std::move(promise))).second;
CHECK(is_inserted);

View File

@ -377,7 +377,7 @@ void CallActor::send_call_log(td_api::object_ptr<td_api::InputFile> log_file, Pr
void CallActor::upload_log_file(FileId file_id, Promise<Unit> &&promise) {
auto *file_manager = G()->td().get_actor_unsafe()->file_manager_.get();
auto upload_file_id = file_manager->dup_file_id(file_id);
auto upload_file_id = file_manager->dup_file_id(file_id, "upload_log_file");
LOG(INFO) << "Ask to upload call log file " << upload_file_id;
class UploadLogFileCallback final : public FileManager::UploadCallback {

View File

@ -6776,7 +6776,8 @@ void ContactsManager::set_profile_photo(const td_api::object_ptr<td_api::InputCh
if (!file_id.is_valid()) {
return promise.set_error(Status::Error(400, "Unknown profile photo ID specified"));
}
return send_update_profile_photo_query(td_->file_manager_->dup_file_id(file_id), photo_id, std::move(promise));
return send_update_profile_photo_query(td_->file_manager_->dup_file_id(file_id, "set_profile_photo"), photo_id,
std::move(promise));
}
case td_api::inputChatPhotoStatic::ID: {
auto photo = static_cast<const td_api::inputChatPhotoStatic *>(input_photo.get());
@ -6809,8 +6810,8 @@ void ContactsManager::set_profile_photo(const td_api::object_ptr<td_api::InputCh
FileId file_id = r_file_id.ok();
CHECK(file_id.is_valid());
upload_profile_photo(td_->file_manager_->dup_file_id(file_id), is_animation, main_frame_timestamp,
std::move(promise));
upload_profile_photo(td_->file_manager_->dup_file_id(file_id, "set_profile_photo"), is_animation,
main_frame_timestamp, std::move(promise));
}
void ContactsManager::send_update_profile_photo_query(FileId file_id, int64 old_photo_id, Promise<Unit> &&promise) {

View File

@ -705,7 +705,7 @@ FileId DocumentsManager::dup_document(FileId new_id, FileId old_id) {
CHECK(new_document == nullptr);
new_document = make_unique<GeneralDocument>(*old_document);
new_document->file_id = new_id;
new_document->thumbnail.file_id = td_->file_manager_->dup_file_id(new_document->thumbnail.file_id);
new_document->thumbnail.file_id = td_->file_manager_->dup_file_id(new_document->thumbnail.file_id, "dup_document");
return new_id;
}

View File

@ -63,7 +63,7 @@ void DownloadManagerCallback::delete_file(FileId file_id) {
}
FileId DownloadManagerCallback::dup_file_id(FileId file_id) {
return td_->file_manager_->dup_file_id(file_id);
return td_->file_manager_->dup_file_id(file_id, "DownloadManagerCallback");
}
void DownloadManagerCallback::get_file_search_text(FileId file_id, FileSourceId file_source_id,

View File

@ -4637,13 +4637,13 @@ 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);
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();
}
return file_manager->dup_file_id(file_id);
return file_manager->dup_file_id(file_id, "dup_message_content");
};
FileId thumbnail_file_id;
@ -4776,7 +4776,8 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
result->photo.photos.back().file_id = fix_file_id(result->photo.photos.back().file_id);
if (has_thumbnail) {
result->photo.photos[0].file_id = td->file_manager_->dup_file_id(result->photo.photos[0].file_id);
result->photo.photos[0].file_id =
td->file_manager_->dup_file_id(result->photo.photos[0].file_id, "dup_message_content photo");
}
return std::move(result);
}

View File

@ -29875,8 +29875,8 @@ void MessagesManager::import_messages(DialogId dialog_id, const td_api::object_p
attached_file_ids.push_back(r_attached_file_id.ok());
}
upload_imported_messages(dialog_id, td_->file_manager_->dup_file_id(file_id), std::move(attached_file_ids), false,
std::move(promise));
upload_imported_messages(dialog_id, td_->file_manager_->dup_file_id(file_id, "import_messages"),
std::move(attached_file_ids), false, std::move(promise));
}
void MessagesManager::upload_imported_messages(DialogId dialog_id, FileId file_id, vector<FileId> attached_file_ids,
@ -29917,8 +29917,9 @@ void MessagesManager::start_import_messages(DialogId dialog_id, int64 import_id,
auto lock_promise = multipromise.get_promise();
for (auto attached_file_id : attached_file_ids) {
upload_imported_message_attachment(dialog_id, import_id, td_->file_manager_->dup_file_id(attached_file_id), false,
multipromise.get_promise());
upload_imported_message_attachment(dialog_id, import_id,
td_->file_manager_->dup_file_id(attached_file_id, "start_import_messages"),
false, multipromise.get_promise());
}
lock_promise.set_value(Unit());
@ -34338,8 +34339,8 @@ void MessagesManager::set_dialog_photo(DialogId dialog_id, const tl_object_ptr<t
return;
}
upload_dialog_photo(dialog_id, td_->file_manager_->dup_file_id(file_id), is_animation, main_frame_timestamp, false,
std::move(promise));
upload_dialog_photo(dialog_id, td_->file_manager_->dup_file_id(file_id, "set_dialog_photo"), is_animation,
main_frame_timestamp, false, std::move(promise));
}
void MessagesManager::send_edit_dialog_photo_query(DialogId dialog_id, FileId file_id,

View File

@ -934,7 +934,7 @@ void NotificationSettingsManager::add_saved_ringtone(td_api::object_ptr<td_api::
return;
}
auto download_file_id = td_->file_manager_->dup_file_id(file_id);
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())

View File

@ -546,7 +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);
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(),
@ -554,7 +554,7 @@ void SetSecureValue::start_upload(FileManager *file_manager, FileId &file_id, Se
.ok();
}
info.file_id = file_manager->dup_file_id(file_id);
info.file_id = file_manager->dup_file_id(file_id, "SetSecureValue");
} else {
force = true;
}

View File

@ -3045,7 +3045,7 @@ FileId StickersManager::dup_sticker(FileId new_id, FileId old_id) {
auto new_sticker = make_unique<Sticker>(*old_sticker);
new_sticker->file_id_ = new_id;
// there is no reason to dup m_thumbnail and premium_animation_file_id
new_sticker->s_thumbnail_.file_id = td_->file_manager_->dup_file_id(new_sticker->s_thumbnail_.file_id);
new_sticker->s_thumbnail_.file_id = td_->file_manager_->dup_file_id(new_sticker->s_thumbnail_.file_id, "dup_sticker");
stickers_.set(new_id, std::move(new_sticker));
return new_id;
}
@ -7643,10 +7643,11 @@ void StickersManager::upload_sticker_file(UserId user_id, FileId file_id, Promis
FileId upload_file_id;
if (td_->file_manager_->get_file_view(file_id).get_type() == FileType::Sticker) {
CHECK(get_input_media(file_id, nullptr, nullptr, string()) == nullptr);
upload_file_id = dup_sticker(td_->file_manager_->dup_file_id(file_id), file_id);
upload_file_id = dup_sticker(td_->file_manager_->dup_file_id(file_id, "upload_sticker_file"), file_id);
} else {
CHECK(td_->documents_manager_->get_input_media(file_id, nullptr, nullptr) == nullptr);
upload_file_id = td_->documents_manager_->dup_document(td_->file_manager_->dup_file_id(file_id), file_id);
upload_file_id =
td_->documents_manager_->dup_document(td_->file_manager_->dup_file_id(file_id, "upload_sticker_file"), file_id);
}
CHECK(upload_file_id.is_valid());

View File

@ -6548,7 +6548,7 @@ void Td::on_request(uint64 id, td_api::preliminaryUploadFile &request) {
return send_error_raw(id, 400, r_file_id.error().message());
}
auto file_id = r_file_id.ok();
auto upload_file_id = file_manager_->dup_file_id(file_id);
auto upload_file_id = file_manager_->dup_file_id(file_id, "preliminaryUploadFile");
file_manager_->upload(upload_file_id, upload_file_callback_, priority, 0);

View File

@ -127,7 +127,8 @@ FileId VideoNotesManager::dup_video_note(FileId new_id, FileId old_id) {
new_video_note->waveform = old_video_note->waveform;
new_video_note->minithumbnail = old_video_note->minithumbnail;
new_video_note->thumbnail = old_video_note->thumbnail;
new_video_note->thumbnail.file_id = td_->file_manager_->dup_file_id(new_video_note->thumbnail.file_id);
new_video_note->thumbnail.file_id =
td_->file_manager_->dup_file_id(new_video_note->thumbnail.file_id, "dup_video_note");
new_video_note->transcription_info = TranscriptionInfo::copy_if_transcribed(old_video_note->transcription_info);
return new_id;
}

View File

@ -137,8 +137,9 @@ FileId VideosManager::dup_video(FileId new_id, FileId old_id) {
CHECK(new_video == nullptr);
new_video = make_unique<Video>(*old_video);
new_video->file_id = new_id;
new_video->thumbnail.file_id = td_->file_manager_->dup_file_id(new_video->thumbnail.file_id);
new_video->animated_thumbnail.file_id = td_->file_manager_->dup_file_id(new_video->animated_thumbnail.file_id);
new_video->thumbnail.file_id = td_->file_manager_->dup_file_id(new_video->thumbnail.file_id, "dup_video");
new_video->animated_thumbnail.file_id =
td_->file_manager_->dup_file_id(new_video->animated_thumbnail.file_id, "dup_video");
return new_id;
}

View File

@ -1086,14 +1086,14 @@ FileManager::FileIdInfo *FileManager::get_file_id_info(FileId file_id) {
return &file_id_info_[file_id.get()];
}
FileId FileManager::dup_file_id(FileId file_id) {
FileId FileManager::dup_file_id(FileId file_id, const char *source) {
int32 file_node_id;
auto *file_node = get_file_node_raw(file_id, &file_node_id);
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;
LOG(INFO) << "Dup file " << file_id << " to " << result << " from " << source;
return result;
}
@ -3196,7 +3196,7 @@ Result<FileId> FileManager::check_input_file_id(FileType type, Result<FileId> re
// URLs in non-secret chats never needs to be reuploaded, so they don't need to be duped
return file_node->main_file_id_;
}
return dup_file_id(file_id);
return dup_file_id(file_id, "check_input_file_id");
}
int32 remote_id = file_id.get_remote();

View File

@ -421,7 +421,7 @@ class FileManager final : public FileLoadManager::Callback {
void init_actor();
FileId dup_file_id(FileId file_id);
FileId dup_file_id(FileId file_id, const char *source);
void on_file_unlink(const FullLocalFileLocation &location);

View File

@ -240,7 +240,7 @@ FileId FileManager::parse_file(ParserT &parser) {
if (file_id.empty()) {
return register_empty(full_generated_location.file_type_);
}
auto download_file_id = dup_file_id(file_id);
auto download_file_id = dup_file_id(file_id, "parse_download_file_id");
full_generated_location.conversion_ = PSTRING() << "#file_id#" << download_file_id.get();
}