[PATCH] Parallel commands don't work when using lftp -c

Fernando Gutierrez <[email protected]> Wed, 1 Jun 2011 18:57:20 +0200
Newsgroups gmane.network.lftp.devel
Message-ID <[email protected]>
--bcaec520eee518f54904a4a96bb5
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

**Problem:
Let's pretend rc has "set cmd:parallels 2;", so we are sure
max_waiting=3D2 (otherwise max_waiting may never be updated as I
explained in my previous mail).
When invoking lftp with "lftp -c 'get http://file1;get
http://file2;get http://file3;' , the files won't be downloaded in
parallel (2 at a time). Get is an example, my point is commands are
not executed in parallel when they are sent to lftp as arguments.

After the initial filefeeder (made when rc is read) dies,
CmdExec::Do() returns too early.

As it has no feeder, it returns in the following code, due to feeder=3D=3Dn=
ull:
if(m !=3D STALL || interactive || !feeder || waiting_num >=3D max_waiting)
=C2=A0 return m;

There are more commands in the buffer (cmd_buf), and if the code
didn't return there, they would be parsed and exec_parsed_command()
would start them (until waiting_num>=3Dmax_waiting)

**Tests:

.lftp/rc:
set cmd:parallel 2;
set cmd:fail-exit false;

lftp -c 'get http://file1;get http://file2;get http://file3;'

It won't work in parallel.

**Fix:
Simply removing !feeder from the if seems to fix it. So you'd have:

if(m !=3D STALL || interactive || waiting_num >=3D max_waiting)
=C2=A0 return m;

And anyway, after that code there is:

if (cmd_buf.Size()=3D=3D0 || partial_cmd) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0if (feeder) { ...stuff... }
=C2=A0 =C2=A0 =C2=A0 =C2=A0return m;
}

If the buffer is empty and there is no feeder, the function returns m,
as it was before the patch. However, if there are things in the
buffer, they are executed. The only change is now commands can be
spawned when the buffer is not empty, regardless of the existence of a
feeder.

--bcaec520eee518f54904a4a96bb5
Content-Type: application/octet-stream; name="parallel_cli.patch"
Content-Disposition: attachment; filename="parallel_cli.patch"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_go4k7jht0

LS0tIG9yaWcvQ21kRXhlYy5jYwkyMDExLTA0LTI5IDA2OjU4OjI3LjAwMDAwMDAwMCArMDIwMAor
KysgcGF0Y2hlZF9sZnRwLTQuMi4zL3NyYy9DbWRFeGVjLmNjCTIwMTEtMDUtMjQgMDk6NTI6MzQu
MDAwMDAwMDAwICswMjAwCkBAIC01NjYsNyArNTY3LDcgQEAKICAgICAgIH0KICAgICAgIGlmKHN0
YXR1c19saW5lICYmIHN0YXR1c19saW5lLT5DYW5TaG93Tm93KCkpCiAJIFNob3dSdW5TdGF0dXMo
c3RhdHVzX2xpbmUpOyAgIC8vIHRoaXMgaXMgb25seSBmb3IgdG9wIGxldmVsIENtZEV4ZWMuCi0g
ICAgICBpZihtICE9IFNUQUxMIHx8IGludGVyYWN0aXZlIHx8ICFmZWVkZXIgfHwgd2FpdGluZ19u
dW0gPj0gbWF4X3dhaXRpbmcpCisgICAgICBpZihtICE9IFNUQUxMIHx8IGludGVyYWN0aXZlIHx8
IHdhaXRpbmdfbnVtID49IG1heF93YWl0aW5nKQogCSByZXR1cm4gbTsKICAgIH0KIAo=
--bcaec520eee518f54904a4a96bb5--