Opened 4 years ago
Closed 4 years ago
#10604 closed defect (bug) (fixed)
class-wp-filesystem-ssh2.php put_contents fails
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 2.9 |
| Component: | Filesystem | Version: | 2.8 |
| Severity: | normal | Keywords: | has-patch commit |
| Cc: |
Description
On certain systems class-wp-filesystem-ssh2->put_contents will fail if the contents of the file are empty.
One possible solution is to check the length of $content and if it is 0 append a space.
This issue prevents many people from upgrading wordpress automatically using ssh.
Could not copy file: /home/complete_blog/public_html/blog/wp-content/upgrade/wordpress-2.8.47/wordpress/wp-includes/js/codepress/engines/khtml.js
Attachments (1)
Change History (8)
comment:1
lostinlafayette — 4 years ago
comment:2
lostinlafayette — 4 years ago
I missed an equal sign, should be ===
- Keywords has-patch needs-testing added
- Milestone changed from Unassigned to 2.9
- Version set to 2.8
-finally-.. :)
Learn something new every day, I didnt realise file_put_contents returns the number of bytes written..
WP_Filesystem_SSH2::put_contents() needs to change from:
function put_contents($file, $contents, $type = '' ) {
$file = ltrim($file, '/');
return file_put_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file, $contents);
}
to
function put_contents($file, $contents, $type = '' ) {
$file = ltrim($file, '/');
return false !== file_put_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file, $contents);
}
So that it returns a boolean result.. False (ie failure) will still come through, but all integer or true values will come through as true.
see patch.
comment:5
lostinlafayette — 4 years ago
The patch works great. I hope to see this included soon.

On second thought the issue is more likely due to file.php not using the correct comparison on the return value of $fs->put_contents. It should be $fs_put_contents(...)==false instead of !$fs_put_contents(...) which when given an empty file will incorrectly fail even though the file was successfully written.