Subject: Re: Option to fail if over quota
From: CGar .
Date: Tue, 31 Mar 2020 21:18:14 +0000
Thank you so much! ๐Ÿ˜Š. That works much better now.

However I've noticed that my script never ends since the return code is the same for a quota exceeded error and any other error, such as file exists.

It would be nice if the return codes were specific to the error type.
For reference this is the little one liner that I'm using:
while :; do if torify $megatools dl "$link"; then break; fi; killall -HUP tor; done
That is mostly just a nice thing to have though. I guess I could instead check for the existence of the file and quit once it exists or something though.

Thanks for your help ๐Ÿ˜Š
________________________________
From: Ondล™ej Jirman <megatools@megous.com>
Sent: 31 March 2020 20:35
To: CGar . <CGar@hotmail.co.uk>
Subject: Re: Option to fail if over quota

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.