File Within VFS-Mount Doesn't Exist?

In a program that I’m working on, I’m struggling to determine whether or not a given file within a mounted multifile exists. (Although it looks like actually reading such a file does work, presuming that it is present…)

Here follows a small example-program demonstrating the issue, as well as a simple multifile containing the text-file that the example-program looks for:

The program:


from direct.showbase.ShowBase import ShowBase

from panda3d.core import VirtualFileSystem, Filename

from direct.stdpy.file import *

import math

from panda3d import __version__ as pandaVersion
print (pandaVersion)

import sys
print (sys.version)


class Game(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        vfs = VirtualFileSystem.getGlobalPtr()
        vfs.mount(Filename("./mew.mf"), Filename("./Mew"), VirtualFileSystem.MFReadOnly)
        
        fileName = Filename("Mew/cat.txt")
        print ("Does the file exist?", fileName.exists())
        fileObj = open("Mew/cat.txt")
        print("File contents:", fileObj.read())
        fileObj.close()


app = Game()
app.run()

And the multifile (zipped, as the forum objects to “.mf” files):

mew.zip (237 Bytes)

The multifile should contain just one file, that being a text-file named “cat.txt” which itself contains the text “Cat!”.

On my machine, at least, this prints the following:

Does the file exist? False
File contents: Cat!

So the file is deemed to not exist–and yet can nevertheless be read. :/

[edit]
As this looks to me like either a bug or unexpected behaviour, I’ve cross-posted the matter to the GitHub issue-tracker, here:

Update: This has been answered by rdb on GitHub, and a bring the answer here for any who might in future encounter a similar issue:

In short, it turns out that the Filename class is unaware of the Virtual File System, and thus its version of the “exists” function doesn’t observe the contents of multifiles.

However, the version of the “exists” function that is found in the VirtualFileSystem class does observe the contents of multifiles, and can thus be used for this purpose.

Indeed, in the example-program above, replacing “fileName.exists()” with “vfs.exists(fileName)” does I find produce the desired output of “True”!

2 Likes