Skip to content

Commit

Permalink
Fix bug in DirectoryArchive::containsFile path handling
Browse files Browse the repository at this point in the history
First bug found as a result of unit tests: the containsFile() code path was
adding an extra trailing slash to the requested filename, which resulted in the
file not being found on UNIX. Probably does not affect the main application
much because nothing is using getFileCount() except for the Python interface
(and now the unit test).
  • Loading branch information
Matthew Mott committed Feb 26, 2019
1 parent 2c6c5d2 commit a4f838e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions radiant/test/data/vfs_root/materials/example.mtr
@@ -0,0 +1,5 @@
textures/orbweaver/drain_grille
{
diffusemap textures/darkmod/metal/flat/heavy_rust_pocked01
bumpmap textures/orbweaver/draingrille_n.tga
}
3 changes: 3 additions & 0 deletions radiant/test/vfsTest.cpp
Expand Up @@ -20,6 +20,8 @@ BOOST_AUTO_TEST_CASE(constructFileSystemModule)

BOOST_AUTO_TEST_CASE(readFilesFromVFS)
{
GlobalOutputStream().setStream(std::cout);

vfs::VirtualFileSystem::ExtensionSet exts;
exts.insert("pk4");

Expand All @@ -31,5 +33,6 @@ BOOST_AUTO_TEST_CASE(readFilesFromVFS)

// Check presence of some files
BOOST_TEST(fs.getFileCount("nothere") == 0);
BOOST_TEST(fs.getFileCount("materials/example.mtr") == 1);
}

6 changes: 3 additions & 3 deletions radiant/vfs/DirectoryArchive.cpp
Expand Up @@ -47,9 +47,9 @@ ArchiveTextFilePtr DirectoryArchive::openTextFile(const std::string& name)

bool DirectoryArchive::containsFile(const std::string& name)
{
UnixPath path(_root);
path.push_filename(name);
return os::fileIsReadable(path);
UnixPath path(_root);
std::string filePath = std::string(path) + name;
return os::fileIsReadable(filePath);
}

void DirectoryArchive::traverse(Visitor& visitor, const std::string& root)
Expand Down
2 changes: 1 addition & 1 deletion radiant/vfs/Doom3FileSystem.cpp
Expand Up @@ -351,7 +351,7 @@ void Doom3FileSystem::removeObserver(Observer& observer)
int Doom3FileSystem::getFileCount(const std::string& filename)
{
int count = 0;
std::string fixedFilename(os::standardPathWithSlash(filename));
std::string fixedFilename(os::standardPath(filename));

for (const ArchiveDescriptor& descriptor : _archives)
{
Expand Down

0 comments on commit a4f838e

Please sign in to comment.