From aab7dadc9a4f55d3a7921a2844ba1bbc18f7fc10 Mon Sep 17 00:00:00 2001
From: Micah Cowan <micah@cowan.name>
Date: Mon, 7 Sep 2009 22:40:25 -0700
Subject: [PATCH] Attempted, but failed, to reproduce bug 22403.

---
 tests/ChangeLog            | 11 ++++++
 tests/FTPServer.pm         |  9 +++--
 tests/Makefile.am          |  1 +
 tests/Test-ftp-bad-list.px | 69 ++++++++++++++++++++++++++++++++++++++
 tests/run-px               |  1 +
 5 files changed, 89 insertions(+), 2 deletions(-)
 create mode 100755 tests/Test-ftp-bad-list.px

diff --git a/tests/ChangeLog b/tests/ChangeLog
index a0f5185a..7c8eb710 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,14 @@
+2009-09-07  Micah Cowan  <micah@cowan.name>
+
+	* FTPServer.pm (FTPServer::run): Pass "server behavior" information to
+	newly-constructed FTPPaths object.
+	(FTPPaths::initialize): Accept "server behavior" hash.
+	(FTPPaths::_format_for_list): If server behavior has "bad_list"
+	set, then always report 0 for the size.
+	* Test-ftp-bad-list.px: Added. Attempts to reproduce bug
+	22403... but doesn't.
+	* run-px, Makefile.am (EXTRA_DIST): Added Test-ftp-bad-list.px.
+
 2009-09-06  Micah Cowan  <micah@cowan.name>
 
 	* WgetTest.pm.in (_setup): Don't expect error codes from
diff --git a/tests/FTPServer.pm b/tests/FTPServer.pm
index 981ddea6..dd065387 100644
--- a/tests/FTPServer.pm
+++ b/tests/FTPServer.pm
@@ -563,7 +563,8 @@ sub run
             print STDERR "in child\n" if $log;
 
             my $conn = { 
-                'paths'           => FTPPaths->new($self->{'_input'}),
+                'paths'           => FTPPaths->new($self->{'_input'},
+                                        $self->{'_server_behavior'}),
                 'socket'          => $socket, 
                 'state'           => $_connection_states{NEWCONN},
                 'dir'             => '/',
@@ -693,7 +694,7 @@ sub new {
 }
 
 sub initialize {
-    my ($self, $urls) = @_;
+    my ($self, $urls, $behavior) = @_;
     my $paths = {_type => 'd'};
 
     # From a path like '/foo/bar/baz.txt', construct $paths such that
@@ -714,6 +715,7 @@ sub initialize {
     }
 
     $self->{'_paths'} = $paths;
+    $self->{'_behavior'} = $behavior;
 }
 
 sub get_info {
@@ -763,6 +765,9 @@ sub _format_for_list {
     my $size = 0;
     if ($info->{'_type'} eq 'f') {
         $size = length  $info->{'content'};
+        if ($self->{'_behavior'}{'bad_list'}) {
+            $size = 0;
+        }
     }
     my $date = strftime ("%b %e %H:%M", localtime);
     return "$mode_str 1  0  0  $size $date $name";
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 768bd084..cd6df8d8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -74,6 +74,7 @@ EXTRA_DIST = FTPServer.pm FTPTest.pm HTTPServer.pm HTTPTest.pm \
              Test-E-k.px \
              Test-ftp.px \
 	     Test-ftp-pasv-fail.px \
+	     Test-ftp-bad-list.px \
              Test-ftp-recursive.px \
              Test-ftp-iri.px \
              Test-ftp-iri-fallback.px \
diff --git a/tests/Test-ftp-bad-list.px b/tests/Test-ftp-bad-list.px
new file mode 100755
index 00000000..11a973fd
--- /dev/null
+++ b/tests/Test-ftp-bad-list.px
@@ -0,0 +1,69 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use FTPTest;
+
+
+###############################################################################
+
+my $afile = <<EOF;
+Some text.
+EOF
+
+my $bfile = <<EOF;
+Some more text.
+EOF
+
+$afile =~ s/\n/\r\n/g;
+$bfile =~ s/\n/\r\n/g;
+
+# code, msg, headers, content
+my %urls = (
+    '/afile.txt' => {
+        content => $afile,
+    },
+    '/bfile.txt' => {
+        content => $bfile,
+    },
+);
+
+my $cmdline = $WgetTest::WGETPATH . " -d -nH -Nc -r ftp://localhost:{{port}}/";
+
+my $expected_error_code = 0;
+
+# Don't need to worry about timestamps, the "bad_list" setting will
+# ensure the sizes don't match expectations, and so they'll always be
+# re-downloaded.
+my %expected_downloaded_files = (
+    'afile.txt' => {
+        content => $afile,
+    },
+    'bfile.txt' => {
+        content => $bfile,
+    },
+);
+
+my %preexisting_files = (
+    'afile.txt' => {
+        content => $afile,
+    },
+    'bfile.txt' => {
+        content => $bfile,
+    },
+);
+
+###############################################################################
+
+my $the_test = FTPTest->new (name => "Test-ftp-bad-list",
+                             input => \%urls, 
+                             cmdline => $cmdline, 
+                             errcode => $expected_error_code, 
+                             output => \%expected_downloaded_files,
+                             existing => \%preexisting_files,
+                             server_behavior => {bad_list => 1});
+exit $the_test->run();
+
+# vim: et ts=4 sw=4
+
diff --git a/tests/run-px b/tests/run-px
index 52101fc6..1a441c7b 100755
--- a/tests/run-px
+++ b/tests/run-px
@@ -27,6 +27,7 @@ my @tests = (
     'Test-E-k.px',
     'Test-ftp.px',
     'Test-ftp-pasv-fail.px',
+    'Test-ftp-bad-list.px',
     'Test-ftp-recursive.px',
     'Test-ftp-iri.px',
     'Test-ftp-iri-fallback.px',