Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #include "net/ftp/ftp_directory_listing_parsers.h" | 5 #include "net/ftp/ftp_directory_listing_parsers.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 | 10 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 entry.type = FtpDirectoryListingEntry::SYMLINK; | 121 entry.type = FtpDirectoryListingEntry::SYMLINK; |
| 122 } else if (columns[0][0] == 'd') { | 122 } else if (columns[0][0] == 'd') { |
| 123 entry.type = FtpDirectoryListingEntry::DIRECTORY; | 123 entry.type = FtpDirectoryListingEntry::DIRECTORY; |
| 124 } else { | 124 } else { |
| 125 entry.type = FtpDirectoryListingEntry::FILE; | 125 entry.type = FtpDirectoryListingEntry::FILE; |
| 126 } | 126 } |
| 127 | 127 |
| 128 if (!IsStringNonNegativeNumber(columns[1])) | 128 if (!IsStringNonNegativeNumber(columns[1])) |
| 129 return false; | 129 return false; |
| 130 | 130 |
| 131 if (!IsStringNonNegativeNumber(columns[4])) | 131 if (!StringToInt64(columns[4], &entry.size)) |
| 132 return false; | 132 return false; |
| 133 if (entry.size < 0) | |
| 134 return false; | |
| 135 if (entry.type != FtpDirectoryListingEntry::FILE) | |
|
wtc
2009/10/28 19:12:08
Why don't we test entry.type earlier, like this?
wtc
2009/10/28 23:51:58
I see. Your code will return false if the format
| |
| 136 entry.size = -1; | |
| 133 | 137 |
| 134 if (!UnixDateListingToTime(columns, &entry.last_modified)) | 138 if (!UnixDateListingToTime(columns, &entry.last_modified)) |
| 135 return false; | 139 return false; |
| 136 | 140 |
| 137 entry.name = columns[8]; | 141 entry.name = columns[8]; |
| 138 | 142 |
| 139 entries_.push(entry); | 143 entries_.push(entry); |
| 140 return true; | 144 return true; |
| 141 } | 145 } |
| 142 | 146 |
| 143 bool FtpLsDirectoryListingParser::EntryAvailable() const { | 147 bool FtpLsDirectoryListingParser::EntryAvailable() const { |
| 144 return !entries_.empty(); | 148 return !entries_.empty(); |
| 145 } | 149 } |
| 146 | 150 |
| 147 FtpDirectoryListingEntry FtpLsDirectoryListingParser::PopEntry() { | 151 FtpDirectoryListingEntry FtpLsDirectoryListingParser::PopEntry() { |
| 148 FtpDirectoryListingEntry entry = entries_.front(); | 152 FtpDirectoryListingEntry entry = entries_.front(); |
| 149 entries_.pop(); | 153 entries_.pop(); |
| 150 return entry; | 154 return entry; |
| 151 } | 155 } |
| 152 | 156 |
| 153 } // namespace net | 157 } // namespace net |
| OLD | NEW |