Ticket #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
Note: See
TracTickets for help on using
tickets.
