Automatically remove incomplete file downloads#117448
Conversation
That should make it possible: verified with python and gdscript ( |
|
Well, it still needs to be fixed until that is implemented. And even then, this could be optional behavior (with a property EDIT: |
|
Thanks! |
|
Hi @KoBeWi I found locally this behavior breaks specific download scenarios, e.g. when fetching release information from a repositories Error OrchestratorUpdaterButton::_send_http_request(const String& p_url, const String& p_filename, const Callable& p_callable) {
HTTPRequest* request = memnew(HTTPRequest);
request->set_download_file(p_filename);
add_child(request);
request->connect(
"request_completed",
callable_mp_lambda(this, [=](int result, int code, const PackedStringArray& headers, const PackedByteArray& data) {
if (result == HTTPRequest::RESULT_SUCCESS && code == 200) {
p_callback.call();
}
}),
CONNECT_ONE_SHOT);
const Error error = request->request(url);
if (error != OK) {
request->queue_free();
}
return OK;
}In this example, the expectation is that we initiate a request to download the file, it gets downloaded and the callback then fires. However, by the time the callback fires, the file no longer exists, and cannot be parsed. In the if (body_len < 0) {
// Chunked transfer is done.
_defer_done(RESULT_SUCCESS, response_code, response_headers, body); // <- this is whats called
return true;
}This allows us to retain the old JSON cache files for release metadata across timer calls to this code, so that in the event of rate limits, we have stale data to work with. We can work around this by using the |
|
I'm also concerned with the description of
Nothing here expresses that the location is simply temporary and will be removed. |
Looks like |
When HTTPRequest fails to download a file (either by download error or manual cancel), the file is saved anyway and is incomplete (corrupted). There is no way to resume the download AFAIK, so there is no reason to keep the file.
This PR makes incomplete files automatically deleted. I don't know much about HTTPRequest, so not sure if there isn't another code path for successful downloads, but I tested that it works correctly with simple requests.
This change is needed for #117072. I tried manually removing the file after failed/canceled request, but it does not work for whatever reason 🤷♂️