~sschwarzer/ftputil#148: 
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
Status
RESOLVED FIXED
Submitter
schwa (unverified)
Assigned to
No-one
Submitted
2 years ago
Updated
2 years ago
Labels
bug library

schwa (unverified) 2 years 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) 2 years 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) 2 years 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.