Set stop_flag_ in FileiDownloader::on_error.

This commit is contained in:
levlam 2024-07-14 00:16:53 +03:00
parent 6564c43d58
commit 34e81dc272
2 changed files with 10 additions and 26 deletions

View File

@ -53,6 +53,7 @@ FileDownloader::FileDownloader(const FullRemoteFileLocation &remote, const Local
void FileDownloader::on_error(Status status) {
fd_.close();
stop_flag_ = true;
callback_->on_error(std::move(status));
}
@ -478,9 +479,7 @@ void FileDownloader::update_downloaded_part(int64 offset, int64 limit, int64 max
void FileDownloader::start_up() {
if (local_.type() == LocalFileLocation::Type::Full) {
on_error(Status::Error("File is already downloaded"));
stop_flag_ = true;
return;
return on_error(Status::Error("File is already downloaded"));
}
if (encryption_key_.is_secure() && !encryption_key_.has_value_hash()) {
LOG(ERROR) << "Can't download Secure file with unknown value_hash";
@ -532,9 +531,7 @@ void FileDownloader::start_up() {
LOG(DEBUG) << "Start downloading a file of size " << size_ << ", part size " << part_size << " and "
<< ready_parts.size() << " ready parts: " << status;
if (status.is_error()) {
on_error(std::move(status));
stop_flag_ = true;
return;
return on_error(std::move(status));
}
if (only_check_) {
parts_manager_.set_checked_prefix_size(0);
@ -566,9 +563,7 @@ void FileDownloader::loop() {
if (status.code() == -1) {
return;
}
on_error(std::move(status));
stop_flag_ = true;
return;
return on_error(std::move(status));
}
}
@ -620,7 +615,6 @@ Status FileDownloader::do_loop() {
TRY_RESULT(query, start_part(part, parts_manager_.get_part_count(), parts_manager_.get_streaming_offset()));
uint64 unique_id = UniqueId::next();
part_map_[unique_id] = std::make_pair(part, query->cancel_slot_.get_signal_new());
// part_map_[unique_id] = std::make_pair(part, query.get_weak());
auto callback = actor_shared(this, unique_id);
if (delay_dispatcher_.empty()) {
@ -668,7 +662,6 @@ void FileDownloader::on_result(NetQueryPtr query) {
auto status = process_check_query(std::move(query));
if (status.is_error()) {
on_error(std::move(status));
stop_flag_ = true;
} else {
loop();
}
@ -701,9 +694,7 @@ void FileDownloader::on_result(NetQueryPtr query) {
return Status::OK();
}();
if (status.is_error()) {
on_error(std::move(status));
stop_flag_ = true;
return;
return on_error(std::move(status));
}
if (next) {
@ -728,7 +719,6 @@ void FileDownloader::on_part_query(Part part, NetQueryPtr query) {
auto status = try_on_part_query(part, std::move(query));
if (status.is_error()) {
on_error(std::move(status));
stop_flag_ = true;
}
}

View File

@ -46,16 +46,14 @@ FileUploader::FileUploader(const LocalFileLocation &local, const RemoteFileLocat
void FileUploader::start_up() {
if (remote_.type() == RemoteFileLocation::Type::Full) {
on_error(Status::Error("File is already uploaded"));
return;
return on_error(Status::Error("File is already uploaded"));
}
// file_size is needed only for partial local locations, but for uploaded partial files
// size is yet unknown or local location is full, so we can always pass 0 here
auto r_prefix_info = on_update_local_location(local_, 0);
if (r_prefix_info.is_error()) {
on_error(r_prefix_info.move_as_error());
return;
return on_error(r_prefix_info.move_as_error());
}
int offset = 0;
@ -110,8 +108,7 @@ void FileUploader::start_up() {
<< (local_is_ready_ ? "exact" : "approximate") << " size " << expected_size << ", part size " << part_size
<< " and " << ready_parts.size() << " ready parts: " << status;
if (status.is_error()) {
on_error(std::move(status));
return;
return on_error(std::move(status));
}
resource_state_.set_unit_size(parts_manager_.get_part_size());
update_estimated_limit();
@ -353,14 +350,12 @@ void FileUploader::update_resources(const ResourceState &other) {
void FileUploader::update_local_file_location(const LocalFileLocation &local) {
auto r_prefix_info = on_update_local_location(local, parts_manager_.get_size_or_zero());
if (r_prefix_info.is_error()) {
on_error(r_prefix_info.move_as_error());
return;
return on_error(r_prefix_info.move_as_error());
}
auto prefix_info = r_prefix_info.move_as_ok();
auto status = parts_manager_.set_known_prefix(prefix_info.size, prefix_info.is_ready);
if (status.is_error()) {
on_error(std::move(status));
return;
return on_error(std::move(status));
}
loop();
}
@ -375,7 +370,6 @@ void FileUploader::loop() {
return;
}
on_error(std::move(status));
return;
}
}