packagefs: Fix attribute indexing

Since the package nodes' attributes are indexed before the VFS has
accessed any of its nodes, the package wasn't open and reading the
attribute data would fail. We do now open the package explicitly in
UnpackingAttributeCookie::IndexAttribute(). Moreover, as an
optimization, we also open the package in Volume::_AddPackageContent(),
so the package file isn't repeatedly opened and closed as its nodes are
being registered.
This commit is contained in:
Ingo Weinhold
2013-05-25 01:12:32 +02:00
parent c3bd329fa2
commit 69a1f1f53f
2 changed files with 19 additions and 0 deletions
@@ -163,6 +163,15 @@ UnpackingAttributeCookie::IndexAttribute(PackageNode* packageNode,
// read the attribute
if (toRead > 0) {
// The package must be open or otherwise reading the attribute data
// may fail.
int fd = packageNode->GetPackage()->Open();
if (fd < 0) {
indexer->DeleteCookie();
return fd;
}
PackageCloser packageCloser(packageNode->GetPackage());
error = ReadAttribute(packageNode, attribute, 0, data, &toRead);
if (error != B_OK) {
indexer->DeleteCookie();
@@ -949,6 +949,16 @@ Volume::_FindPackage(const char* fileName) const
status_t
Volume::_AddPackageContent(Package* package, bool notify)
{
// Open the package. We don't need the FD here, but this is an optimization.
// The attribute indices may want to read the package nodes' attributes and
// the package file would be opened and closed for each attribute instance.
// Since Package keeps and shares the FD as long as at least one party has
// the package open, we prevent that.
int fd = package->Open();
if (fd < 0)
RETURN_ERROR(fd);
PackageCloser packageCloser(package);
status_t error = fPackageFSRoot->AddPackage(package);
if (error != B_OK)
RETURN_ERROR(error);