Opened 6 years ago

Closed 6 years ago

Last modified 6 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:

Description

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

Change History (4)

comment:1 Changed 6 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 6 years ago by schwa

  • Keywords isfile isdir islink directory traceback documentation added
  • Milestone set to 2.7.2
  • Status changed from new to assigned

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 6 years ago by schwa

  • Resolution set to fixed
  • Status changed from assigned to closed

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

comment:4 Changed 6 years ago by schwa

  • Milestone changed from 2.7.2 to 2.8
Note: See TracTickets for help on using tickets.