Skip to content

Commit

Permalink
FS|libcore: Improved behavior of linked packages
Browse files Browse the repository at this point in the history
A package's root folder may be behind a link. PackageLoader will
also accept package source files in addition to the .pack link files
when looking for loaded packages.
  • Loading branch information
skyjake committed Oct 17, 2017
1 parent 23a3106 commit 3ba4356
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
12 changes: 6 additions & 6 deletions doomsday/sdk/libcore/include/de/filesys/package.h
Expand Up @@ -95,18 +95,18 @@ class DENG2_PUBLIC Package : public IObject
virtual ~Package();

/**
* Returns the ".pack" file of the Package. In practice, this may be a ZIP folder,
* an regular folder, or a link to a DataBundle. You should use sourceFile() to
* access the file where the package's contents are stored in.
* Returns the ".pack" file of the Package. In practice, this may be a ZIP folder, an
* regular folder, or a link to a DataBundle. You should use sourceFile() to access
* the file in which the package's contents are actually stored.
*
* @return Package file.
*/
File const &file() const;

/**
* Returns the original source file of the package, where the package's
* contents are being sourced from. This is usually the file referenced
* by the "path" member in the package metadata.
* Returns the original source file of the package, where the package's contents are
* being sourced from. This is usually the file referenced by the "path" member in
* the package metadata.
*/
File const &sourceFile() const;

Expand Down
5 changes: 3 additions & 2 deletions doomsday/sdk/libcore/src/filesys/package.cpp
Expand Up @@ -45,6 +45,7 @@ static String const PACKAGE_IMPORT_PATH("package.importPath");
static String const PACKAGE_REQUIRES ("package.requires");
static String const PACKAGE_RECOMMENDS ("package.recommends");
static String const PACKAGE_EXTRAS ("package.extras");
static String const PACKAGE_PATH ("package.path");
static String const PACKAGE_TAGS ("package.tags");

static String const VAR_ID ("ID");
Expand Down Expand Up @@ -143,13 +144,13 @@ File const &Package::file() const

File const &Package::sourceFile() const
{
return App::rootFolder().locate<File const>(objectNamespace().gets("package.path"));
return App::rootFolder().locate<File const>(objectNamespace().gets(PACKAGE_PATH));
}

Folder const &Package::root() const
{
d->verifyFile();
return expectedAs<Folder>(d->file);
return expectedAs<Folder>(&d->file->target());
}

Record &Package::objectNamespace()
Expand Down
8 changes: 7 additions & 1 deletion doomsday/sdk/libcore/src/filesys/packageloader.cpp
Expand Up @@ -59,10 +59,16 @@ DENG2_PIMPL(PackageLoader)
*/
Package *tryFindLoaded(File const &file) const
{
// qDebug() << "tryFindLoaded:" << Package::identifierForFile(file);
// for (auto i = loaded.begin(); i != loaded.end(); ++i)
// {
// qDebug() << " currently loaded:" << i.key() << "file:" << i.value()->file().path() << "source:" << i.value()->sourceFile().path();
// }
LoadedPackages::const_iterator found = loaded.constFind(Package::identifierForFile(file));
if (found != loaded.constEnd())
{
if (&found.value()->file() == &file)
auto const &pkg = *found.value();
if (&pkg.file() == &file || &pkg.sourceFile() == &file)
{
return found.value();
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libcore/src/filesys/remotefeedprotocol.cpp
Expand Up @@ -89,7 +89,7 @@ void RemoteFeedMetadataPacket::addFile(File const &file, String const &prefix)
fileMeta->addNumber("type", status.type() == File::Type::File? 0 : 1);
if (status.type() == File::Type::Folder)
{
fileMeta->addNumber("size", file.as<Folder>().contents().size());
fileMeta->addNumber("size", file.target().as<Folder>().contents().size());
}
else
{
Expand Down

0 comments on commit 3ba4356

Please sign in to comment.