Opened 10 years ago
Closed 10 years ago
#30815 closed defect (bug) (fixed)
WP_Filesystem_FTPext::exists() returns false if directory exists but is empty
Reported by: | Unyson | Owned by: | ocean90 |
---|---|---|---|
Milestone: | 4.2 | Priority: | normal |
Severity: | normal | Version: | 2.8 |
Component: | Filesystem API | Keywords: | has-patch needs-unit-tests |
Focuses: | Cc: |
Description
/** * Check if a file or directory exists. * * @since 2.5.0 * @abstract * @param string $file Path to file/directory. * @return bool Whether $file exists or not. */ public function exists($file) { $list = @ftp_nlist($this->link, $file); return !empty($list); //empty list = no file, so invert. }
This method doesn't take in consideration that directory may exist but is empty.
The WP_Filesystem_FTPext::is_dir()
method works correct (returns true
). But the exists()
method must be fixed, I think it's a major bug.
Attachments (2)
Change History (9)
This ticket was mentioned in Slack in #core by ocean90. View the logs.
10 years ago
#4
@
10 years ago
- Keywords needs-unit-tests added
@ocean90: Latest patch still applies, though I suppose having unit tests here would be helpful to test the intent.
#5
@
10 years ago
- Severity changed from critical to normal
- Version changed from 4.1 to 2.8
From dd32: "I think the documentation is wrong though, since it's obviously designed to check for a file not a directory"
#6
@
10 years ago
Basically I revert to using the logic of the Direct class in all cases such as this, Direct uses file_exists()
, so it should be both file & directory.
The SSH2 class trims the trailing slash off a path to cause it to list the contents of the parent directory, limited to that child node.
So; The patch here looks good.
Noticed the same while testing #30802.
Setup:
30815.patch checks if $file is an empty directory.