~sschwarzer/ftputil#66: 
FTPHost.path.isfile() on nonexistent path raises PermanentError

If you call path.isfile() on a non existent path like so:

from ftputil import FTPHost

SERVER = 'localhost'
USER = ''
PASSWORD = ''

if __name__ == '__main__':

    ftph = FTPHost(SERVER, USER, PASSWORD)
    print ftph.path.isfile('/asd/txt')

a PermanentError? is raised instead of returning False as would be expected from the docstring to isfile:

"A non-existing path does _not_ cause a PermanentError."

The stack trace:

Traceback (most recent call last):
  File "D:\ECLIPSE-WS\ftputilplay\src\ftpup.py", line 10, in <module>
    print ftph.path.isfile('/asd/txt')
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\ftp_path.py", line 111, in isfile
    path, _exception_for_missing_path=False)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\__init__.py", line 896, in stat
    return self._stat._stat(path, _exception_for_missing_path)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\ftp_stat.py", line 624, in _stat
    _exception_for_missing_path)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\ftp_stat.py", line 578, in __call_with_parser_retry
    result = method(*args, **kwargs)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\ftp_stat.py", line 543, in _real_stat
    lstat_result = self._real_lstat(path, _exception_for_missing_path)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\ftp_stat.py", line 502, in _real_lstat
    for stat_result in self._stat_results_from_dir(dirname):
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\ftp_stat.py", line 419, in _stat_results_from_dir
    lines = self._host_dir(path)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\ftp_stat.py", line 411, in _host_dir
    return self._host._dir(path)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\__init__.py", line 847, in _dir
    descend_deeply=True)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\__init__.py", line 590, in _robust_ftp_command
    self.chdir(path)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\__init__.py", line 615, in chdir
    ftp_error._try_with_oserror(self._session.cwd, path)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\ftp_error.py", line 136, in _try_with_oserror
    raise PermanentError(*exc.args)
ftputil.ftp_error.PermanentError: 550 CWD failed. "/asd": directory not found.
Debugging info: ftputil 2.7.1, Python 2.7.3 (win32)

seems to indicate the _exception_for_missing_path is not carried when calling for stat_result in self._stat_results_from_dir(dirname) in real_lstat, line 502

I've patched around this by catching PermanentErrors? in isfile, but this is a quick and dirty solution and I'm hoping for a cleaner fix in the mainline.

Thx for your nice library!

Mario

Status
RESOLVED FIXED
Submitter
ftputiluser (unverified)
Assigned to
No-one
Submitted
9 years ago
Updated
9 years ago
Labels
bug library

ftputiluser (unverified) 9 years ago · edit

The problem also occurs with path.isfile. Also it is probably related to Ticket #39 but visible in a more common case.

schwa (unverified) 9 years ago · edit

Thanks for the report.

I'll look into it, but it might possibly take until the next month since I'm going to prepare my PyCon DE talks during the next weekends. :-)

schwa (unverified) 9 years ago · edit

I could reproduce the problem. It should be fixed by changeset 4f39a848e55ac15f5e17c72bdb052d8677bef788.

Register here or Log in to comment, or comment via email.