Skip to content

Commit

Permalink
FS|Fixed|libcore: Reinterpreted files are indexed in the file system
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Nov 25, 2016
1 parent 8539d09 commit 9b7c1a9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
5 changes: 4 additions & 1 deletion doomsday/sdk/libcore/include/de/filesys/fileindex.h
Expand Up @@ -141,7 +141,10 @@ class DENG2_PUBLIC FileIndex

void print() const;

// C++ iterator:
QList<File *> files() const;

protected:
// C++ iterator (not thread safe):
typedef Index::const_iterator const_iterator;
Index::const_iterator begin() const;
Index::const_iterator end() const;
Expand Down
2 changes: 2 additions & 0 deletions doomsday/sdk/libcore/src/filesys/file.cpp
Expand Up @@ -341,6 +341,7 @@ File *File::reinterpret()
if (folder)
{
folder->remove(*this);
deindex();
}

original->flush();
Expand All @@ -357,6 +358,7 @@ File *File::reinterpret()
if (folder)
{
folder->add(result);
fileSystem().index(*result);
}
return result;
}
Expand Down
12 changes: 12 additions & 0 deletions doomsday/sdk/libcore/src/filesys/fileindex.cpp
Expand Up @@ -217,4 +217,16 @@ void FileIndex::print() const
}
}

QList<File *> FileIndex::files() const
{
DENG2_GUARD_READ(d);

QList<File *> list;
for (auto i = begin(); i != end(); ++i)
{
list.append(i->second);
}
return list;
}

} // namespace de
3 changes: 3 additions & 0 deletions doomsday/sdk/libcore/src/filesys/filesystem.cpp
Expand Up @@ -258,6 +258,8 @@ void FileSystem::index(File &file)
{
d->index.maybeAdd(file);

//qDebug() << "[FS] Indexing" << file.path() << DENG2_TYPE_NAME(file);

// Also make an entry in the type index.
d->getTypeIndex(DENG2_TYPE_NAME(file)).maybeAdd(file);

Expand Down Expand Up @@ -293,6 +295,7 @@ File &FileSystem::copySerialized(String const &sourcePath, String const &destina
if (behavior & ReinterpretDestination)
{
// We can now reinterpret and populate the contents of the archive.
//qDebug() << "[FS] Reinterpreting" << dest->path();
dest = dest->reinterpret();
}

Expand Down
23 changes: 12 additions & 11 deletions doomsday/sdk/libcore/src/filesys/packageloader.cpp
Expand Up @@ -241,45 +241,46 @@ DENG2_PIMPL(PackageLoader)

void listPackagesInIndex(FileIndex const &index, StringList &list)
{
for (auto i = index.begin(); i != index.end(); ++i)
foreach (File *indexedFile, index.files())
{
if (shouldIgnoreFile(*i->second)) continue;
if (shouldIgnoreFile(*indexedFile)) continue;

if (i->first.fileNameExtension() == ".pack")
String const fileName = indexedFile->name();
if (fileName.fileNameExtension() == ".pack")
{
try
{
File &file = *i->second;
String path = file.path();
//File &file = *indexedFile;
String path = indexedFile->path();

// The special persistent data package should be ignored.
if (path == "/home/persist.pack") continue;
if (path == QStringLiteral("/home/persist.pack")) continue;

// Check the metadata.
checkPackage(file);
checkPackage(*indexedFile);

list.append(path);
}
catch (Package::NotPackageError const &er)
{
// This is usually a .pack folder used only for nesting.
LOG_RES_XVERBOSE("\"%s\": %s") << i->first << er.asText();
LOG_RES_XVERBOSE("\"%s\": %s") << fileName << er.asText();
}
catch (Package::ValidationError const &er)
{
// Not a loadable package.
LOG_RES_MSG("\"%s\": Package is invalid: %s") << i->first << er.asText();
LOG_RES_MSG("\"%s\": Package is invalid: %s") << fileName << er.asText();
}
catch (Parser::SyntaxError const &er)
{
LOG_RES_WARNING("\"%s\": Package has a Doomsday Script syntax error: %s")
<< i->first << er.asText();
<< fileName << er.asText();
}
catch (Info::SyntaxError const &er)
{
// Not a loadable package.
LOG_RES_WARNING("\"%s\": Package has a syntax error: %s")
<< i->first << er.asText();
<< fileName << er.asText();
}

/// @todo Store the errors so that the UI can show a list of
Expand Down

0 comments on commit 9b7c1a9

Please sign in to comment.