Remove now unsafe FileId constructors.

GitOrigin-RevId: eb3e37f4056ff6b967e4fd3d9b310fdc0e7602a1
This commit is contained in:
levlam 2018-03-07 02:37:39 +03:00
parent f041bf4cc8
commit c35bc1c0fc
6 changed files with 16 additions and 17 deletions

View File

@ -974,7 +974,7 @@ td_api::object_ptr<td_api::remoteFile> copy(const td_api::remoteFile &obj) {
template <> template <>
td_api::object_ptr<td_api::file> copy(const td_api::file &obj) { td_api::object_ptr<td_api::file> copy(const td_api::file &obj) {
FileId file_id(obj.id_); FileId file_id(obj.id_, 0); // wrong, but there should be no difference for get_file_object
if (file_id.is_valid()) { if (file_id.is_valid()) {
return G()->td().get_actor_unsafe()->file_manager_.get()->get_file_object(file_id); return G()->td().get_actor_unsafe()->file_manager_.get()->get_file_object(file_id);
} else { } else {

View File

@ -3242,7 +3242,7 @@ vector<FileId> StickersManager::get_attached_sticker_file_ids(const vector<int32
result.reserve(int_file_ids.size()); result.reserve(int_file_ids.size());
for (auto int_file_id : int_file_ids) { for (auto int_file_id : int_file_ids) {
FileId file_id(int_file_id); FileId file_id(int_file_id, 0);
if (get_sticker(file_id) == nullptr) { if (get_sticker(file_id) == nullptr) {
LOG(WARNING) << "Can't find sticker " << file_id; LOG(WARNING) << "Can't find sticker " << file_id;
continue; continue;

View File

@ -2829,7 +2829,7 @@ class GetAttachedStickerSetsRequest : public RequestActor<> {
public: public:
GetAttachedStickerSetsRequest(ActorShared<Td> td, uint64 request_id, int32 file_id) GetAttachedStickerSetsRequest(ActorShared<Td> td, uint64 request_id, int32 file_id)
: RequestActor(std::move(td), request_id), file_id_(file_id) { : RequestActor(std::move(td), request_id), file_id_(file_id, 0) {
} }
}; };
@ -5127,7 +5127,7 @@ void Td::on_request(uint64 id, const td_api::getPublicMessageLink &request) {
void Td::on_request(uint64 id, const td_api::getFile &request) { void Td::on_request(uint64 id, const td_api::getFile &request) {
CHECK_AUTH(); CHECK_AUTH();
send_closure(actor_id(this), &Td::send_result, id, file_manager_->get_file_object(FileId(request.file_id_))); send_closure(actor_id(this), &Td::send_result, id, file_manager_->get_file_object(FileId(request.file_id_, 0)));
} }
void Td::on_request(uint64 id, td_api::getRemoteFile &request) { void Td::on_request(uint64 id, td_api::getRemoteFile &request) {
@ -5954,9 +5954,9 @@ void Td::on_request(uint64 id, const td_api::downloadFile &request) {
if (!(1 <= priority && priority <= 32)) { if (!(1 <= priority && priority <= 32)) {
return send_error_raw(id, 5, "Download priority must be in [1;32] range"); return send_error_raw(id, 5, "Download priority must be in [1;32] range");
} }
file_manager_->download(FileId(request.file_id_), download_file_callback_, priority); file_manager_->download(FileId(request.file_id_, 0), download_file_callback_, priority);
auto file = file_manager_->get_file_object(FileId(request.file_id_), false); auto file = file_manager_->get_file_object(FileId(request.file_id_, 0), false);
if (file->id_ == 0) { if (file->id_ == 0) {
return send_error_raw(id, 400, "Invalid file id"); return send_error_raw(id, 400, "Invalid file id");
} }
@ -5967,7 +5967,7 @@ void Td::on_request(uint64 id, const td_api::downloadFile &request) {
void Td::on_request(uint64 id, const td_api::cancelDownloadFile &request) { void Td::on_request(uint64 id, const td_api::cancelDownloadFile &request) {
CHECK_AUTH(); CHECK_AUTH();
file_manager_->download(FileId(request.file_id_), nullptr, request.only_if_pending_ ? -1 : 0); file_manager_->download(FileId(request.file_id_, 0), nullptr, request.only_if_pending_ ? -1 : 0);
send_closure(actor_id(this), &Td::send_result, id, make_tl_object<td_api::ok>()); send_closure(actor_id(this), &Td::send_result, id, make_tl_object<td_api::ok>());
} }
@ -5997,7 +5997,7 @@ void Td::on_request(uint64 id, td_api::uploadFile &request) {
void Td::on_request(uint64 id, const td_api::cancelUploadFile &request) { void Td::on_request(uint64 id, const td_api::cancelUploadFile &request) {
CHECK_AUTH(); CHECK_AUTH();
file_manager_->upload(FileId(request.file_id_), nullptr, 0, 0); file_manager_->upload(FileId(request.file_id_, 0), nullptr, 0, 0);
send_closure(actor_id(this), &Td::send_result, id, make_tl_object<td_api::ok>()); send_closure(actor_id(this), &Td::send_result, id, make_tl_object<td_api::ok>());
} }
@ -6046,7 +6046,7 @@ void Td::on_request(uint64 id, const td_api::deleteFile &request) {
} }
}); });
send_closure(file_manager_actor_, &FileManager::delete_file, FileId(request.file_id_), std::move(query_promise), send_closure(file_manager_actor_, &FileManager::delete_file, FileId(request.file_id_, 0), std::move(query_promise),
"td_api::deleteFile"); "td_api::deleteFile");
} }

View File

@ -21,12 +21,11 @@ class FileId {
public: public:
FileId() = default; FileId() = default;
explicit FileId(int32 file_id, int32 remote_id) : id(file_id), remote_id(remote_id) { FileId(int32 file_id, int32 remote_id) : id(file_id), remote_id(remote_id) {
} }
explicit FileId(int32 file_id) : FileId(file_id, 0) { template <class T1, class T2, typename = std::enable_if_t<std::is_convertible<T1, int32>::value>,
} typename = std::enable_if_t<std::is_convertible<T2, int32>::value>>
template <class T, typename = std::enable_if_t<std::is_convertible<T, int32>::value>> FileId(T1 file_id, T2 remote_id) = delete;
FileId(T file_id) = delete;
bool empty() const { bool empty() const {
return id <= 0; return id <= 0;

View File

@ -621,7 +621,7 @@ void FileManager::try_forget_file_id(FileId file_id) {
CHECK(it != file_node->file_ids_.end()); CHECK(it != file_node->file_ids_.end());
file_node->file_ids_.erase(it); file_node->file_ids_.erase(it);
*info = FileIdInfo(); *info = FileIdInfo();
empty_file_ids_.push_back(FileId(file_id.get())); empty_file_ids_.push_back(file_id.get());
} }
FileId FileManager::register_empty(FileType type) { FileId FileManager::register_empty(FileType type) {
@ -1997,7 +1997,7 @@ FileId FileManager::next_file_id() {
if (!empty_file_ids_.empty()) { if (!empty_file_ids_.empty()) {
auto res = empty_file_ids_.back(); auto res = empty_file_ids_.back();
empty_file_ids_.pop_back(); empty_file_ids_.pop_back();
return res; return FileId{res, 0};
} }
FileId res(static_cast<int32>(file_id_info_.size()), 0); FileId res(static_cast<int32>(file_id_info_.size()), 0);
// LOG(ERROR) << "NEXT file_id " << res; // LOG(ERROR) << "NEXT file_id " << res;

View File

@ -393,7 +393,7 @@ class FileManager : public FileLoadManager::Callback {
std::map<FileDbId, int32> pmc_id_to_file_node_id_; std::map<FileDbId, int32> pmc_id_to_file_node_id_;
vector<FileIdInfo> file_id_info_; vector<FileIdInfo> file_id_info_;
vector<FileId> empty_file_ids_; vector<int32> empty_file_ids_;
vector<std::unique_ptr<FileNode>> file_nodes_; vector<std::unique_ptr<FileNode>> file_nodes_;
ActorOwn<FileLoadManager> file_load_manager_; ActorOwn<FileLoadManager> file_load_manager_;
ActorOwn<FileGenerateManager> file_generate_manager_; ActorOwn<FileGenerateManager> file_generate_manager_;