#38 closed defect (fixed)
If cache size is zero, FTPHost.listdir causes an IndexError
Reported by: | schwa | Owned by: | schwa |
---|---|---|---|
Priority: | minor | Milestone: | 2.4.2 |
Component: | Library | Version: | 2.4.2b |
Keywords: | cache, resize, IndexError | Cc: |
Description
If the cache size for an FTPHost
instance is explicitly set to zero, a following listdir
call raises an IndexError
:
>>> import ftputil >>> host = ftputil.FTPHost("ftp.debian.org", "anonymous", "foo@example.com") >>> host.stat_cache.resize(0) >>> host.listdir(host.curdir) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "ftputil.py", line 795, in listdir return self._stat.listdir(path) File "ftp_stat.py", line 565, in listdir return self.__call_with_parser_retry(self._real_listdir, path) File "ftp_stat.py", line 543, in __call_with_parser_retry result = method(*args, **kwargs) File "ftp_stat.py", line 422, in _real_listdir self._lstat_cache[loop_path] = stat_result File "ftp_stat_cache.py", line 168, in __setitem__ self._cache[path] = stat_result File "lrucache.py", line 164, in __setitem__ lru = heappop(self.__heap) IndexError: index out of range
On the other hand, disabling the cache explicitly doesn't raise an exception:
>>> host.stat_cache.disable() >>> host.listdir(host.curdir) ['debian']
Change History (3)
comment:1 Changed 12 years ago by
Status: | new → assigned |
---|
comment:2 Changed 12 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Fixed in changeset 882.
comment:3 Changed 10 years ago by
I changed the policy for zero size caches in [2640715ee9aa]. They're no longer allowed.
Using a cache size of zero never was intuitive. Actually, it was only used to implicitly clear the cache. This now can be done with a new clear
method.
Note: See
TracTickets for help on using
tickets.
One can notice a corresponding behavior in the lrucache module itself:
I guess, it's a question of philosophy if trying to store an item in a zero-sized cache should be considered a bug. In my opinion, this should be handled transparently, as if the cache was full. It shouldn't raise an exception, but perhaps effectively discard the to-be cache entry (in the same way older entries are discarded from the cache when it's full and new entries arrive).