fox-it / dissect.target

The Dissect module tying all other Dissect modules together. It provides a programming API and command line tools which allow easy access to various data sources inside disk images or file collections (a.k.a. targets).
GNU Affero General Public License v3.0
38 stars 44 forks source link

Add support for `recursive` flag in `glob`/`glob_ext` #293

Open rukisec opened 1 year ago

rukisec commented 1 year ago

Hi,

I have run into the following problem. When using glob or glob_ext files are only discovered within the first sub-directory, so there seems to be no real recursion. Is this intended?

Example:

>>> t = Target.open("test/2020JimmyWilson.E01")

>>> for h in t.fs.glob("/sysvol/Users/Jimmy Wilson/Desktop/Robert Ripoff/Shesa*"):
            print(h)

Output: /sysvol/Users/Jimmy Wilson/Desktop/Robert Ripoff/Shesa Hippo.jpg

>>> for h in t.fs.glob("/sysvol/Users/Jimmy Wilson/Desktop/**/Shesa*"):
            print(h)

Output: /sysvol/Users/Jimmy Wilson/Desktop/Robert Ripoff/Shesa Hippo.jpg

>>> for h in t.fs.glob("/sysvol/Users/Jimmy Wilson/**/Shesa*"):
            print(h)

Output:

Schamper commented 1 year ago

Hi @ruukaku!

The t.fs.glob and t.fs.glob_ext functions should behave similarly to the Python glob module. It does indeed look like we do not yet support the recursive=True flag that it documented for that module. That's something we could definitely add.

However, it's recommended that you actually use the pathlib API to access the filesystem contents:

t.fs.path("sysvol/Users/Jimmy Wilson").rglob("Shesa*")

Pretty much all read-only functionality that is documented for the official pathlib module will work. A TargetPath object returned from t.fs.path("/") will behave the same as a pathlib.Path object! In fact, isinstance(t.fs.path("/"), pathlib.Path) == True.

rukisec commented 1 year ago

The t.fs.glob and t.fs.glob_ext functions should behave similarly to the Python glob module. It does indeed look like we do not yet support the recursive=True flag that it documented for that module. That's something we could definitely add.

I would very much appreciate that :)

However, it's recommended that you actually use the pathlib API to access the filesystem contents:

Thanks for the recommendation