brenthuisman / par2deep

Produce, verify and repair par2 files recursively.
GNU Lesser General Public License v3.0
84 stars 8 forks source link

Escape special characters in work directory #24

Closed proItheus closed 5 months ago

proItheus commented 5 months ago

The program can't properly handle directory with special chars (in glob) like [abcd].

I think it's because you've forgotten escaping self.directory in par2deep.py.

https://github.com/brenthuisman/par2deep/blob/ae275e6930fa8592331e3a0f9dd499f196df6e12/par2deep/par2deep.py#L146

brenthuisman commented 5 months ago

Took me a while to see what you mean. This problem pops up only when self.directory contains, for instance, a dir called [abcd]. If it's a subdir of self.directory, no problem.

I'm going to pass the blame on to glob.glob. glob.escapeing the string first solves the issues.

But maybe I've found a good excuse to switch to Pathlib:

> a = "/Users/brent/tmp/[abcd]" # this is a dir I created for this test.
> os.path.exists(a)
True
> glob.glob(a+'/*')
[]
> glob.glob(r""+a+'/*') # a trick pulled from some SO post, which should hopefully let glob know to not interpret `[]` as special chars
[]
> list(Path(a).glob('*'))
[PosixPath('/Users/brent/tmp/[abcd]/11 - Rubber Bullets.m4a'), PosixPath('/Users/brent/tmp/[abcd]/11 - Rubber Bullets.m4a.vol000+100.par2'), PosixPath('/Users/brent/tmp/[abcd]/11 - Rubber Bullets.m4a.par2')]
proItheus commented 5 months ago

Ah, by escape I mean using glob.escape("[abcd]"). It will turn [abcd] into [[]abcd].