Opened 14 years ago
Closed 14 years ago
#10604 closed defect (bug) (fixed)
class-wp-filesystem-ssh2.php put_contents fails
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 2.9 | Priority: | normal |
Severity: | normal | Version: | 2.8 |
Component: | Filesystem API | Keywords: | has-patch commit |
Focuses: | 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)
#4
@
14 years ago
- 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.
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.