db/upnp: use iterator in Namei()

This commit is contained in:
Max Kellermann 2014-01-21 23:32:42 +01:00
parent 7260d7883c
commit aa1eb2f40d

View File

@ -480,13 +480,14 @@ UpnpDatabase::Namei(ContentDirectoryService &server,
std::string objid(rootid); std::string objid(rootid);
// Walk the path elements, read each directory and try to find the next one // Walk the path elements, read each directory and try to find the next one
for (unsigned int i = 0; i < vpath.size(); i++) { for (auto i = vpath.begin(), end = vpath.end(), last = std::prev(end);
i != end; ++i) {
UPnPDirContent dirbuf; UPnPDirContent dirbuf;
if (!server.readDir(handle, objid.c_str(), dirbuf, error)) if (!server.readDir(handle, objid.c_str(), dirbuf, error))
return false; return false;
// Look for the name in the sub-container list // Look for the name in the sub-container list
UPnPDirObject *child = dirbuf.FindObject(vpath[i].c_str()); UPnPDirObject *child = dirbuf.FindObject(i->c_str());
if (child == nullptr) if (child == nullptr)
break; break;
@ -497,7 +498,7 @@ UpnpDatabase::Namei(ContentDirectoryService &server,
case UPnPDirObject::Type::CONTAINER: case UPnPDirObject::Type::CONTAINER:
objid = child->m_id; // Next readdir target objid = child->m_id; // Next readdir target
if (i == vpath.size() - 1) { if (i == last) {
// The last element in the path was found and it's // The last element in the path was found and it's
// a container, we're done // a container, we're done
odirent = std::move(*child); odirent = std::move(*child);
@ -508,7 +509,7 @@ UpnpDatabase::Namei(ContentDirectoryService &server,
case UPnPDirObject::Type::ITEM: case UPnPDirObject::Type::ITEM:
// If this is the last path elt, we found the target, // If this is the last path elt, we found the target,
// else it does not exist // else it does not exist
if (i == vpath.size() - 1) { if (i == last) {
odirent = std::move(*child); odirent = std::move(*child);
return true; return true;
} else { } else {