Ticket #8904: archivemember-2.patch
File archivemember-2.patch, 6.0 KB (added by , 17 years ago) |
---|
-
archive.cpp
30 30 namespace Common { 31 31 32 32 33 int Archive:: matchPattern(StringList &list, const String &pattern) {33 int Archive::listMatchingMembers(ArchiveMemberList &list, const String &pattern) { 34 34 // Get all "names" (TODO: "files" ?) 35 StringList allNames;36 getAllNames(allNames);35 ArchiveMemberList allNames; 36 listMembers(allNames); 37 37 38 38 int matches = 0; 39 39 … … 41 41 String lowercasePattern = pattern; 42 42 lowercasePattern.toLowercase(); 43 43 44 StringList::iterator it = allNames.begin();44 ArchiveMemberList::iterator it = allNames.begin(); 45 45 for ( ; it != allNames.end(); it++) { 46 if ( it->matchString(lowercasePattern)) {46 if ((*it)->getName().matchString(lowercasePattern)) { 47 47 list.push_back(*it); 48 48 matches++; 49 49 } … … 52 52 return matches; 53 53 } 54 54 55 /** 56 * FSDirectoryMemeber is the implementation of ArchiveMember used by 57 * by FSDirectory. It is right now a light wrapper or FSNode. 58 */ 59 class FSDirectoryMember : public ArchiveMember { 60 FilesystemNode _node; 55 61 62 public: 63 FSDirectoryMember(FilesystemNode &node) : _node(node) { 64 } 65 66 /* 67 NOTE/FIXME: since I assume that the only use case for getName() 68 is for error messages, I am returning the full path of the node 69 here. This seems better than we did before, when matchPattern 70 and getAllNames used to work with StringList, and we used to 71 put the relative path of the file to the list instead. 72 */ 73 String getName() const { 74 return _node.getPath(); 75 } 76 77 SeekableReadStream *open() { 78 return _node.openForReading(); 79 } 80 }; 81 82 typedef SharedPtr<FSDirectoryMember> FSDirectoryMemberPtr; 83 84 56 85 FSDirectory::FSDirectory(const FilesystemNode &node, int depth) 57 86 : _node(node), _cached(false), _depth(depth) { 58 87 } … … 159 188 160 189 } 161 190 162 int FSDirectory:: matchPattern(StringList &list, const String &pattern) {191 int FSDirectory::listMatchingMembers(ArchiveMemberList &list, const String &pattern) { 163 192 if (!_node.isDirectory()) 164 193 return 0; 165 194 … … 169 198 _cached = true; 170 199 } 171 200 172 // Small optimization: Ensure the StringList has to grow at most once173 l ist.reserve(list.size() + _fileCache.size());174 175 // Add all filenames from our cache201 String lowercasePattern(pattern); 202 lowercasePattern.toLowercase(); 203 204 int matches = 0; 176 205 NodeCache::iterator it = _fileCache.begin(); 177 206 for ( ; it != _fileCache.end(); it++) { 178 if (it->_key.matchString(pattern)) 179 list.push_back(it->_key); 207 if ((*it)._key.matchString(lowercasePattern)) { 208 list.push_back(FSDirectoryMemberPtr(new FSDirectoryMember((*it)._value))); 209 matches++; 210 } 180 211 } 181 182 return _fileCache.size(); 212 return matches; 183 213 } 184 214 185 int FSDirectory:: getAllNames(StringList &list) {186 if (!_node.isDirectory())187 return 0; 215 int FSDirectory::listMembers(ArchiveMemberList &list) { 216 return listMatchingMembers(list, "*"); 217 } 188 218 189 // Cache dir data190 if (!_cached) {191 cacheDirectoryRecursive(_node, _depth, "");192 _cached = true;193 }194 219 195 // Small optimization: Ensure the StringList has to grow at most once196 list.reserve(list.size() + _fileCache.size());197 198 // Add all filenames from our cache199 NodeCache::iterator it = _fileCache.begin();200 for ( ; it != _fileCache.end(); it++) {201 list.push_back((*it)._key);202 }203 204 return _fileCache.size();205 }206 220 207 221 208 222 … … 288 302 return false; 289 303 } 290 304 291 int SearchSet:: matchPattern(StringList &list, const String &pattern) {305 int SearchSet::listMatchingMembers(ArchiveMemberList &list, const String &pattern) { 292 306 int matches = 0; 293 307 294 308 ArchiveList::iterator it = _list.begin(); 295 309 for ( ; it != _list.end(); it++) { 296 matches += (*it)._arc-> matchPattern(list, pattern);310 matches += (*it)._arc->listMatchingMembers(list, pattern); 297 311 } 298 312 299 313 return matches; 300 314 } 301 315 302 int SearchSet:: getAllNames(StringList &list) {316 int SearchSet::listMembers(ArchiveMemberList &list) { 303 317 int matches = 0; 304 318 305 319 ArchiveList::iterator it = _list.begin(); 306 320 for ( ; it != _list.end(); it++) { 307 matches += (*it)._arc-> getAllNames(list);321 matches += (*it)._arc->listMembers(list); 308 322 } 309 323 310 324 return matches; -
archive.h
36 36 37 37 namespace Common { 38 38 39 class ArchiveMember { 40 public: 41 virtual ~ArchiveMember() { } 42 virtual String getName() const = 0; 43 virtual SeekableReadStream *open() = 0; 44 }; 45 46 typedef List<SharedPtr<ArchiveMember> > ArchiveMemberList; 47 39 48 /** 40 49 * FilePtr is a convenient way to keep track of a SeekableReadStream without 41 50 * having to worry about releasing its memory. … … 63 72 * 64 73 * @return the number of names added to list 65 74 */ 66 virtual int matchPattern(StringList &list, const String &pattern);75 virtual int listMatchingMembers(ArchiveMemberList &list, const String &pattern); 67 76 68 77 /** 69 78 * Add all the names present in the Archive to list. Returned … … 72 81 * 73 82 * @return the number of names added to list 74 83 */ 75 virtual int getAllNames(StringList &list) = 0;84 virtual int listMembers(ArchiveMemberList &list) = 0; 76 85 77 86 /** 78 87 * Create a stream bound to a file in the archive. … … 138 147 FSDirectory *getSubDirectory(const String &name); 139 148 140 149 virtual bool hasFile(const String &name); 141 virtual int matchPattern(StringList &list, const String &pattern);142 virtual int getAllNames(StringList &list);150 virtual int listMatchingMembers(ArchiveMemberList &list, const String &pattern); 151 virtual int listMembers(ArchiveMemberList &list); 143 152 virtual SeekableReadStream *openFile(const String &name); 144 153 }; 145 154 … … 192 201 void setPriority(const String& name, uint priority); 193 202 194 203 virtual bool hasFile(const String &name); 195 virtual int matchPattern(StringList &list, const String &pattern);196 virtual int getAllNames(StringList &list);204 virtual int listMatchingMembers(ArchiveMemberList &list, const String &pattern); 205 virtual int listMembers(ArchiveMemberList &list); 197 206 198 207 /** 199 208 * Implements openFile from Archive base class. The current policy is