Bug 63259 - [PATCH] FTP symlinks are checked twice
Summary: [PATCH] FTP symlinks are checked twice
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Optional Tasks (show other bugs)
Version: 1.10.5
Hardware: All All
: P2 enhancement (vote)
Target Milestone: 1.10.7
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-12 18:59 UTC by Eugène Adell
Modified: 2019-05-17 04:28 UTC (History)
1 user (show)



Attachments
patch (888 bytes, patch)
2019-03-12 19:03 UTC, Eugène Adell
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eugène Adell 2019-03-12 18:59:38 UTC
When running FTP task to list files, the directories are checked twice. This is not necessary and has a negative impact on performance.

This happens because the current code checks if an entry (of the list) is a directory, and if it is not it then tries to determine if this is a file by - again - checking if it is not a directory.

The network capture then looks like this, for example with two "rfc7296.txt: No such file or directory" :

19:48:21.101597 IP 4.31.198.44.21 > 185.47.63.113.54412: Flags [P.], seq 5804:5845, ack 1278, win 22, options [nop,nop,TS val 134060372 ecr 2715006999], length 41
EH.]..@./......,./?q....6.Z.'.:]....m......
...T....257 "/rfc/std" is the current directory

19:48:21.101958 IP 185.47.63.113.54412 > 4.31.198.44.21: Flags [P.], seq 1278:1298, ack 5845, win 140, options [nop,nop,TS val 2715007166 ecr 134060372], length 20
E..HE,@.@.2../?q...,....'.:]6.Z.....~......
.......TCWD ../rfc7296.txt

19:48:21.268070 IP 4.31.198.44.21 > 185.47.63.113.54412: Flags [P.], seq 5845:5892, ack 1298, win 22, options [nop,nop,TS val 134060414 ecr 2715007166], length 47
EH.c..@./......,./?q....6.Z.'.:q...........
...~....550 ../rfc7296.txt: No such file or directory

19:48:21.268350 IP 185.47.63.113.54412 > 4.31.198.44.21: Flags [P.], seq 1298:1303, ack 5892, win 140, options [nop,nop,TS val 2715007333 ecr 134060414], length 5
E..9E-@.@.2../?q...,....'.:q6.[.....OY.....
...e...~PWD

19:48:21.415135 IP 4.31.198.44.21 > 185.47.63.113.54412: Flags [P.], seq 5892:5933, ack 1303, win 22, options [nop,nop,TS val 134060455 ecr 2715007333], length 41
EH.]..@./......,./?q....6.[.'.:v....k......
.......e257 "/rfc/std" is the current directory

19:48:21.415478 IP 185.47.63.113.54412 > 4.31.198.44.21: Flags [P.], seq 1303:1323, ack 5933, win 140, options [nop,nop,TS val 2715007480 ecr 134060455], length 20
E..HE.@.@.2../?q...,....'.:v6.[*....|......
........CWD ../rfc7296.txt

19:48:21.563730 IP 4.31.198.44.21 > 185.47.63.113.54412: Flags [P.], seq 5933:5980, ack 1323, win 22, options [nop,nop,TS val 134060492 ecr 2715007480], length 47
EH.c..@./......,./?q....6.[*'.:............
........550 ../rfc7296.txt: No such file or directory

19:48:21.564411 IP 185.47.63.113.54412 > 4.31.198.44.21: Flags [P.], seq 1323:1328, ack 5980, win 140, options [nop,nop,TS val 2715007629 ecr 134060492], length 5
E..9E/@.@.2../?q...,....'.:.6.[Y....Mr.....
........PWD

19:48:21.711083 IP 4.31.198.44.21 > 185.47.63.113.54412: Flags [P.], seq 5980:6021, ack 1328, win 22, options [nop,nop,TS val 134060529 ecr 2715007629], length 41
EH.]..@./......,./?q....6.[Y'.:.....j......
........257 "/rfc/std" is the current directory

19:48:21.711398 IP 185.47.63.113.54412 > 4.31.198.44.21: Flags [P.], seq 1328:1346, ack 6021, win 140, options [nop,nop,TS val 2715007776 ecr 134060529], length 18
E..FE0@.@.2../?q...,....'.:.6.[......E.....
... ....CWD ../rfc20.txt

example target is :

  <target name="listingWithSymlinks">
    <ftp action="list"
       listing="listingWithSymlinks.txt"
       server="ftp.ietf.org"
       port="21"
       remotedir="/rfc/std"
       userid="anonymous"
       password="anonymous" >
       <fileset dir="." defaultexcludes="no" includes="*" />
    </ftp>
  </target>

output is 
listingWithSymlinks:
      [ftp] Opening FTP connection to ftp.ietf.org
      [ftp] connected
      [ftp] logging in to FTP server
      [ftp] login succeeded
      [ftp] changing the remote directory to /rfc/std
      [ftp] listing files
fileset: Setup scanner in dir /home/eadell/tests/ftpant with patternSet{ includes: [*] excludes: [] }
      [ftp] 92 files listed
      [ftp] disconnecting

BUILD SUCCESSFUL
Total time: 1 minute 19 seconds
Comment 1 Eugène Adell 2019-03-12 19:03:13 UTC
Created attachment 36482 [details]
patch

patch which removes the double check to determine whether it is a directory or a file

the network capture now looks like this :

19:45:34.367012 IP 4.31.198.44.21 > 185.47.63.113.54409: Flags [P.], seq 3779:3820, ack 702, win 22, options [nop,nop,TS val 134018688 ecr 2714840262], length 41
EH.]..@./.Zb...,./?q.......h7..c...........
......,.257 "/rfc/std" is the current directory

19:45:34.367628 IP 185.47.63.113.54409 > 4.31.198.44.21: Flags [P.], seq 702:722, ack 3820, win 140, options [nop,nop,TS val 2714840432 ecr 134018688], length 20
E..H.g@.@..\./?q...,....7..c...............
..-p....CWD ../rfc7011.txt

19:45:34.537721 IP 4.31.198.44.21 > 185.47.63.113.54409: Flags [P.], seq 3820:3867, ack 722, win 22, options [nop,nop,TS val 134018730 ecr 2714840432], length 47
EH.c..@./.Z[...,./?q........7..w...........
......-p550 ../rfc7011.txt: No such file or directory

19:45:34.538756 IP 185.47.63.113.54409 > 4.31.198.44.21: Flags [P.], seq 722:727, ack 3867, win 140, options [nop,nop,TS val 2714840603 ecr 134018730], length 5
E..9.h@.@..j./?q...,....7..w........eT.....
........PWD

19:45:34.708577 IP 4.31.198.44.21 > 185.47.63.113.54409: Flags [P.], seq 3867:3908, ack 727, win 22, options [nop,nop,TS val 134018773 ecr 2714840603], length 41
EH.]..@./.Z`...,./?q........7..|...........
........257 "/rfc/std" is the current directory

19:45:34.709179 IP 185.47.63.113.54409 > 4.31.198.44.21: Flags [P.], seq 727:747, ack 3908, win 140, options [nop,nop,TS val 2714840773 ecr 134018773], length 20
E..H.i@.@..Z./?q...,....7..|...............
........CWD ../rfc7296.txt
Comment 2 Jaikiran Pai 2019-05-17 04:28:26 UTC
Hello Eugène,

Thank you for the patch. I've reviewed it and it looks fine to me. I made a minor change to the comment in the patch and merged this upstream https://gitbox.apache.org/repos/asf?p=ant.git;a=commitdiff;h=0259c0b981e997a67a926c5303e8906250b30bb6