Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Unified Diff: net/ftp/ftp_directory_listing_parser_ls.cc

Issue 6096006: FTP: correctly handle directory listings containing "Permission denied" errors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/ftp/ftp_directory_listing_parser_ls.cc
diff --git a/net/ftp/ftp_directory_listing_parser_ls.cc b/net/ftp/ftp_directory_listing_parser_ls.cc
index 9660eabf164dbedbbffad4d5735f053893d5e9ad..34ef519de661c4dbd78c4bc26f58766a7fa4d62c 100644
--- a/net/ftp/ftp_directory_listing_parser_ls.cc
+++ b/net/ftp/ftp_directory_listing_parser_ls.cc
@@ -45,6 +45,21 @@ bool LooksLikeUnixPermissionsListing(const string16& text) {
(text.substr(10).empty() || text.substr(10) == ASCIIToUTF16("+")));
}
+bool LooksLikePermissionDeniedError(const string16& text) {
+ // Try to recognize a three-part colon-separated error message:
+ //
+ // 1. ftpd server name
+ // 2. directory name (often just ".")
+ // 3. message text (usually "Permission denied")
+ std::vector<string16> parts;
+ base::SplitString(CollapseWhitespace(text, false), ':', &parts);
+
+ if (parts.size() != 3)
+ return false;
+
+ return parts[2] == ASCIIToUTF16("Permission denied");
+}
+
bool DetectColumnOffset(const std::vector<string16>& columns,
const base::Time& current_time, int* offset) {
base::Time time;
@@ -125,8 +140,12 @@ bool FtpDirectoryListingParserLs::ConsumeLine(const string16& line) {
}
int column_offset;
- if (!DetectColumnOffset(columns, current_time_, &column_offset))
- return false;
+ if (!DetectColumnOffset(columns, current_time_, &column_offset)) {
+ // If we can't recognize a normal listing line, maybe it's an error?
+ // In that case, just ignore the error, but still recognize the data
+ // as valid listing.
+ return LooksLikePermissionDeniedError(line);
+ }
// We may receive file names containing spaces, which can make the number of
// columns arbitrarily large. We will handle that later. For now just make
« no previous file with comments | « net/ftp/ftp_directory_listing_buffer_unittest.cc ('k') | net/ftp/ftp_directory_listing_parser_ls_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698