Skip to content

'glob' method from direct.stdpy.glob does not function as intended when patterns are used #1675

Description

@BoggTech

Description

When using the glob module from stdpy, the intent is that it will work with files mounted on the VFS. However, this isn't the case, and it instead functions like the normal glob module when a pattern is involved.

Upon looking at the function itself, the helper function glob1 uses os.listdir rather than stdpy's implementation file.listdir, which fails to see any files that are mounted on the VFS (line 55).

Steps to Reproduce

Here's a code snippet i threw together that creates some example files and showcase the issue:

import os
from panda3d.core import Multifile, VirtualFileSystem, Filename
import direct.stdpy.glob as glob

# create two seperate directories on the disk
if not os.path.exists("test1"):
    os.mkdir("test1")
if not os.path.exists("test2"):
    os.mkdir("test2")

# create a multifile in test1 and give it a dummy file
if not os.path.exists("example.txt"):
    file = open("example.txt", "w")
    file.write("Hello World!")
    file.close()

mf = Multifile()
mf.open_write("test1/example.mf")
mf.add_subfile("example/example.txt", Filename.textFilename("example.txt"), 0)

# mount that multifile to test2 with the VFS
vfs = VirtualFileSystem.get_global_ptr()
vfs.mount(mf, "./test2/", VirtualFileSystem.MF_read_only)

# glob w/ literal basename (no pattern)
print("[No Pattern] Files Found: " + str(glob.glob("test2/example/example.txt")))
# glob with a pattern
print("[Pattern] Files Found: " + str(glob.glob("test2/example/*")))

Running this code produces the output

[No Pattern] Files Found: ['test2/example/example.txt']
[Pattern] Files Found: []

which is wrong, as it should be showing example.txt when using the pattern as well.

For good measure, here's the output I get on Windows when I replace the usage of os.listdir with file.listdir:

[No Pattern] Files Found: ['test2/example/example.txt']
[Pattern] Files Found: ['test2/example\\example.txt']

which looks to have some issues with using unix-style paths (seemingly because of the usage of os.path.join on line 45).

Environment

  • Operating system: Windows 10
  • System architecture: x64
  • Panda3D version: 1.10.14
  • Installation method: SDK
  • Python version (if using Python): 3.11.9

Metadata

Metadata

Assignees

No one assigned

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions