[ftp] Don't append slash to NLST in exists() #1438
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We're using multiple different thirdparty ftp servers and we've now stumbled over a case, where the
.exists(name)
call did not work correctly.In this case, the
location
looked likeftp://username:password@example.org:21/
, so it CWDs to the root. In the root there were multiple files like 20240724.txt, 20240723.txt,...When I used
storage.exists("20240724.txt")
it returned False (note,allow_overwrite
was False). The problem with this setup is, that this exists-call resulted in the call ofself._connection.nlst("/")
(which is also not correct, if a different path/CWD is used), which returned a list with items like["/20240724.txt", "/20240723.txt"]
, so all items have a "/" prepended, therefore the actual name "20240724.txt" cannot be found. This is not the case, whenself._connection.nlst("")
is used.I've tested my change (where no "/" gets added) with other setups (e.g. other CWD and also with the changes of #1433 with no CWD at all), and in all cases my fix works without issues. Therefore I'm hoping we can merge this.
With this change the code is also consistent with similar usages, like
.size()
, where no slash gets added either.