Closed mon closed 4 years ago
This breaks test_Filepath_is_equal_to_relative_path.
This seems works, but it's not efficient again:
hash(self) == hash(type(self)(other))
Maybe adding an instance cache to the Filepath class would work?
Ah shoot, I totally forgot the tests - I'll try and implement an instance cache later this evening and make sure the tests pass!
The instance cache was just an idea. Feel free to think of a better solution.
Now that I'm running the tests I see the problem caused by FilePath objects being compared to PosixPath objects.
Would you be opposed to "upgrading" any pathlib.Path style objects by replacing their __class__
member with FilePath
, so they gain hash caching without having to mess with the caller? It feels a bit hacky but it would work quite well.
Actually no, considering the existing tests this is a horrible idea. I'll think of something better.
Alright! I think this suits much better, since torrent creation is always comparing Filepaths to Filepaths, a simple instance check lets us be speedy without breaking semantics during tests.
Looks great. Very simple. Thanks!
I made a bugfix release.
I have a torrent with several thousand files, and the
filter_func
'sin
check performs__eq__
on theFilepath
objects. Because it doesn't use the hash cache, it performs over 30 million lstats, bringing the disk to its knees.By using the cached hash, my torrent is constructed quickly.