diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-29 07:39:52 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-29 07:39:52 +0000 |
commit | 7f80210ea48c97eda990d3fcf4f190db5542e75d (patch) | |
tree | c0cfec217c8f96ca36a9f4c00170d6a0edf0ad5a /net/ftp | |
parent | aeb53b34fe924159674c8f15a6a82d23e470e487 (diff) | |
download | chromium_src-7f80210ea48c97eda990d3fcf4f190db5542e75d.zip chromium_src-7f80210ea48c97eda990d3fcf4f190db5542e75d.tar.gz chromium_src-7f80210ea48c97eda990d3fcf4f190db5542e75d.tar.bz2 |
Also parse file size in new FTP LIST parsing code.
TEST=Covered by net_unittests.
BUG=25520
Review URL: http://codereview.chromium.org/343022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30445 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/ftp')
-rw-r--r-- | net/ftp/ftp_directory_listing_buffer_unittest.cc | 22 | ||||
-rw-r--r-- | net/ftp/ftp_directory_listing_parsers.cc | 6 | ||||
-rw-r--r-- | net/ftp/ftp_directory_listing_parsers.h | 1 | ||||
-rw-r--r-- | net/ftp/ftp_directory_listing_parsers_unittest.cc | 10 |
4 files changed, 24 insertions, 15 deletions
diff --git a/net/ftp/ftp_directory_listing_buffer_unittest.cc b/net/ftp/ftp_directory_listing_buffer_unittest.cc index a98e412..f72a151 100644 --- a/net/ftp/ftp_directory_listing_buffer_unittest.cc +++ b/net/ftp/ftp_directory_listing_buffer_unittest.cc @@ -48,26 +48,27 @@ TEST(FtpDirectoryListingBufferTest, Parse) { StringTokenizer tokenizer(expected_listing, "\r\n"); while (tokenizer.GetNext()) lines.push_back(tokenizer.token()); - ASSERT_EQ(0U, lines.size() % 7); + ASSERT_EQ(0U, lines.size() % 8); - for (size_t i = 0; i < lines.size() / 7; i++) { - std::string type(lines[7 * i]); - std::string name(lines[7 * i + 1]); + for (size_t i = 0; i < lines.size() / 8; i++) { + std::string type(lines[8 * i]); + std::string name(lines[8 * i + 1]); + int64 size = StringToInt64(lines[8 * i + 2]); SCOPED_TRACE(StringPrintf("Filename: %s", name.c_str())); int year; - if (lines[7 * i + 2] == "current") { + if (lines[8 * i + 3] == "current") { base::Time::Exploded now_exploded; base::Time::Now().LocalExplode(&now_exploded); year = now_exploded.year; } else { - year = StringToInt(lines[7 * i + 2]); + year = StringToInt(lines[8 * i + 3]); } - int month = StringToInt(lines[7 * i + 3]); - int day_of_month = StringToInt(lines[7 * i + 4]); - int hour = StringToInt(lines[7 * i + 5]); - int minute = StringToInt(lines[7 * i + 6]); + int month = StringToInt(lines[8 * i + 4]); + int day_of_month = StringToInt(lines[8 * i + 5]); + int hour = StringToInt(lines[8 * i + 6]); + int minute = StringToInt(lines[8 * i + 7]); ASSERT_TRUE(buffer.EntryAvailable()); net::FtpDirectoryListingEntry entry = buffer.PopEntry(); @@ -83,6 +84,7 @@ TEST(FtpDirectoryListingBufferTest, Parse) { } EXPECT_EQ(UTF8ToUTF16(name), entry.name); + EXPECT_EQ(size, entry.size); base::Time::Exploded time_exploded; entry.last_modified.LocalExplode(&time_exploded); diff --git a/net/ftp/ftp_directory_listing_parsers.cc b/net/ftp/ftp_directory_listing_parsers.cc index c1a7f76..60cef80 100644 --- a/net/ftp/ftp_directory_listing_parsers.cc +++ b/net/ftp/ftp_directory_listing_parsers.cc @@ -128,8 +128,12 @@ bool FtpLsDirectoryListingParser::ConsumeLine(const string16& line) { if (!IsStringNonNegativeNumber(columns[1])) return false; - if (!IsStringNonNegativeNumber(columns[4])) + if (!StringToInt64(columns[4], &entry.size)) return false; + if (entry.size < 0) + return false; + if (entry.type != FtpDirectoryListingEntry::FILE) + entry.size = -1; if (!UnixDateListingToTime(columns, &entry.last_modified)) return false; diff --git a/net/ftp/ftp_directory_listing_parsers.h b/net/ftp/ftp_directory_listing_parsers.h index 4fda042..2f402e7 100644 --- a/net/ftp/ftp_directory_listing_parsers.h +++ b/net/ftp/ftp_directory_listing_parsers.h @@ -23,6 +23,7 @@ struct FtpDirectoryListingEntry { Type type; string16 name; + int64 size; // File size, in bytes. -1 if not applicable. // Last modified time, in local time zone. base::Time last_modified; diff --git a/net/ftp/ftp_directory_listing_parsers_unittest.cc b/net/ftp/ftp_directory_listing_parsers_unittest.cc index e74d421..b7d9499 100644 --- a/net/ftp/ftp_directory_listing_parsers_unittest.cc +++ b/net/ftp/ftp_directory_listing_parsers_unittest.cc @@ -13,6 +13,7 @@ struct SingleLineTestData { const char* input; net::FtpDirectoryListingEntry::Type type; const char* filename; + int64 size; int year; int month; int day_of_month; @@ -32,6 +33,7 @@ class FtpDirectoryListingParsersTest : public testing::Test { net::FtpDirectoryListingEntry entry = parser->PopEntry(); EXPECT_EQ(test_case.type, entry.type); EXPECT_EQ(UTF8ToUTF16(test_case.filename), entry.name); + EXPECT_EQ(test_case.size, entry.size); base::Time::Exploded time_exploded; entry.last_modified.LocalExplode(&time_exploded); @@ -54,16 +56,16 @@ TEST_F(FtpDirectoryListingParsersTest, Ls) { const struct SingleLineTestData good_cases[] = { { "-rw-r--r-- 1 ftp ftp 528 Nov 01 2007 README", - net::FtpDirectoryListingEntry::FILE, "README", + net::FtpDirectoryListingEntry::FILE, "README", 528, 2007, 11, 1, 0, 0 }, { "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11 directory", - net::FtpDirectoryListingEntry::DIRECTORY, "directory", + net::FtpDirectoryListingEntry::DIRECTORY, "directory", -1, now_exploded.year, 5, 15, 18, 11 }, { "lrwxrwxrwx 1 0 0 26 Sep 18 2008 pub -> vol/1/.CLUSTER/var_ftp/pub", - net::FtpDirectoryListingEntry::SYMLINK, "pub", + net::FtpDirectoryListingEntry::SYMLINK, "pub", -1, 2008, 9, 18, 0, 0 }, { "lrwxrwxrwx 1 0 0 3 Oct 12 13:37 mirror -> pub", - net::FtpDirectoryListingEntry::SYMLINK, "mirror", + net::FtpDirectoryListingEntry::SYMLINK, "mirror", -1, now_exploded.year, 10, 12, 13, 37 }, }; for (size_t i = 0; i < arraysize(good_cases); i++) { |