Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#66 closed defect (fixed)

FTPHost.path.isfile() on nonexistent path raises PermanentError

Reported by: ftputiluser Owned by: schwa
Priority: minor Milestone: 2.8
Component: Library Version: 2.7.1
Keywords: isfile, isdir, islink, directory, traceback, documentation Cc:


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

from ftputil import FTPHost

SERVER = 'localhost'
USER = ''

if __name__ == '__main__':

    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\", line 10, in <module>
    print ftph.path.isfile('/asd/txt')
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\", line 111, in isfile
    path, _exception_for_missing_path=False)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\", line 896, in stat
    return self._stat._stat(path, _exception_for_missing_path)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\", line 624, in _stat
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\", line 578, in __call_with_parser_retry
    result = method(*args, **kwargs)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\", line 543, in _real_stat
    lstat_result = self._real_lstat(path, _exception_for_missing_path)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\", line 502, in _real_lstat
    for stat_result in self._stat_results_from_dir(dirname):
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\", line 419, in _stat_results_from_dir
    lines = self._host_dir(path)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\", line 411, in _host_dir
    return self._host._dir(path)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\", line 847, in _dir
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\", line 590, in _robust_ftp_command
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\", line 615, in chdir
    ftp_error._try_with_oserror(self._session.cwd, path)
  File "D:\TEMP\ftputilvirtpy\lib\site-packages\ftputil\", 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!


Change History (4)

comment:1 Changed 9 years ago by ftputiluser

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

comment:2 Changed 9 years ago by schwa

Keywords: isfile isdir islink directory traceback documentation added
Milestone: 2.7.2
Status: newassigned

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. :-)

comment:3 Changed 9 years ago by schwa

Resolution: fixed
Status: assignedclosed

I could reproduce the problem. It should be fixed by changeset [31a1b5455047].

comment:4 Changed 9 years ago by schwa

Note: See TracTickets for help on using tickets.