Fix parsing of directories listing on a specific ftp server
authorMarco Scarpetta <marcoscarpetta02@gmail.com>
Wed, 1 Feb 2017 10:29:08 +0000 (11:29 +0100)
committerMaximiliano Curia <maxy@debian.org>
Wed, 5 Apr 2017 08:10:59 +0000 (09:10 +0100)
Directories listing on ftp servers like ftp://ftp-dee.poliba.it/ are now parsed correctly.

BUG: 375610
REVIEW: 129905
FIXED-IN: 5.31

Gbp-Pq: Name Fix-parsing-of-directories-listing-on-a-specific-ftp-serv.patch

src/ioslaves/ftp/ftp.cpp

index 2e129fcdc334dfd1e37ef9255860ca6cff1cd0b1..e41c7648d5e7da05266206904294ceb14b651225 100644 (file)
@@ -1669,24 +1669,35 @@ bool Ftp::ftpReadDir(FtpEntry &de)
             }
         }
 
+        // This is needed for ftp servers with a directory listing like this (#375610):
+        // drwxr-xr-x               folder        0 Mar 15 15:50 directory_name
+        if (strcmp(p_junk, "folder") == 0) {
+            p_date_1 = p_group;
+            p_date_2 = p_size;
+            p_size = p_owner;
+            p_group = nullptr;
+            p_owner = nullptr;
+        }
         // Check whether the size we just read was really the size
         // or a month (this happens when the server lists no group)
         // Used to be the case on sunsite.uio.no, but not anymore
         // This is needed for the Netware case, too.
-        if (!isdigit(*p_size)) {
+        else if (!isdigit(*p_size)) {
             p_date_1 = p_size;
+            p_date_2 = strtok(nullptr, " ");
             p_size = p_group;
             p_group = 0;
             qCDebug(KIO_FTP) << "Size didn't have a digit -> size=" << p_size << " date_1=" << p_date_1;
         } else {
-            p_date_1 = strtok(NULL, " ");
+            p_date_1 = strtok(nullptr, " ");
+            p_date_2 = strtok(nullptr, " ");
             qCDebug(KIO_FTP) << "Size has a digit -> ok. p_date_1=" << p_date_1;
         }
 
-        if (p_date_1 != 0 &&
-                (p_date_2 = strtok(NULL, " ")) != 0 &&
-                (p_date_3 = strtok(NULL, " ")) != 0 &&
-                (p_name = strtok(NULL, "\r\n")) != 0) {
+        if (p_date_1 != nullptr &&
+                p_date_2 != nullptr &&
+                (p_date_3 = strtok(nullptr, " ")) != nullptr &&
+                (p_name = strtok(nullptr, "\r\n")) != nullptr) {
             {
                 QByteArray tmp(p_name);
                 if (p_access[0] == 'l') {