Opened 4 years ago

Closed 4 years ago

#10604 closed defect (bug) (fixed)

class-wp-filesystem-ssh2.php put_contents fails

Reported by: lostinlafayette Owned by: dd32
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)

10604.diff (591 bytes) - added by dd32 4 years ago.
props lostinlafayette

Download all attachments as: .zip

Change History (8)

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.

I missed an equal sign, should be ===

Umm... I been getting this exact error. I'll look into it as well.

comment:4   dd324 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.

dd324 years ago

props lostinlafayette

The patch works great. I hope to see this included soon.

comment:6   dd324 years ago

  • Keywords commit added; needs-testing removed
  • Resolution set to fixed
  • Status changed from new to closed

(In [11818]) Fix class-wp-filesystem-ssh2 put_contents() for empty files, props lostinlafayette dd32, fixes #10604

Note: See TracTickets for help on using tickets.