Subject: Re: Option to fail if over quota
From: Ondřej Jirman
Date: Tue, 31 Mar 2020 21:35:26 +0200
Hi,

On Tue, Mar 31, 2020 at 07:19:39PM +0000, CGar . wrote:
> Hi, I'm looking to create a script that will reset my IP when mega returns 509 over quota.
> However it is quite difficult with the way megadl is setup. It runs for a very long time before it fails.
> 
> Is there an option to have it fail much faster?
> That way I can catch that with the return code and get a new IP and start again.
> 
> I suck at C but have managed to reduce the time by editing the line:
> const gint64 retry_timeout = 1000ll * 1000 * 60 * 640;
> https://megous.com/git/megatools/tree/lib/mega.c#n4455
> But I'm not sure if that is the most appropriate way.

Try with this change, it should fail immediately when quota is reached,
and leave the half-downloaded file in place for resume later:

diff --git a/lib/mega.c b/lib/mega.c
index 84422c0..5cffce5 100644
--- a/lib/mega.c
+++ b/lib/mega.c
@@ -4465,6 +4465,11 @@ retry:
                http_free(h);
 
                if (!download_ok) {
+                       if (g_error_matches(local_err, HTTP_ERROR, HTTP_ERROR_BANDWIDTH_LIMIT)) {
+                               g_propagate_prefixed_error(err, local_err, "Data download failed: ");
+                               goto err_noremove;
+                       }
+
                        // retry timeout reached
                        if (g_get_monotonic_time() > end_time) {
                                g_propagate_prefixed_error(err, local_err, "Data download failed: ");




regards,
	o.