Wrong query results for empty path

A user reported that several FTPHost methods return wrong results when given an empty path, for example

  • FTPHost.path.exists("") -> True
  • FTPHost.path.isdir("") -> True
schwa (unverified)
Assigned to
10 months ago
10 months ago
bug library

schwa (unverified) 10 months ago · edit

The reason for the odd behavior is that all the FTPHost methods immediately change a path argument to an absolute path without checking the argument beforehand. Therefore, turning "" into an absolute path always gives the absolute path of the current directory.

To fix this problem, the incoming path should be compared against "" and if that's the value, the path should be considered non-existent, or an exception should be raised. The behavior will depend on the concrete method. For example, FTPHost.path.exists should return False whereas FTPHost.open probably should raise a PermanentError.

schwa (unverified) 10 months ago · edit

For the record: Curiously, using an empty path under Linux on an ext4 file system results in a "file not found" error, even when creating a file, for example with touch "".

schwa (unverified) 10 months ago · edit

  • FTPHost.path.isdir, isfile and islink now return False for an empty path.
  • Most public methods raise an FTPIOError for an empty path. The exception is FTPHost.chdir. The reason is explained in commit d615279cd0f7dfc560f9b4eac3bd88572d25750b.
Register here or Log in to comment, or comment via email.