WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#10604 closed defect (bug) (fixed)

class-wp-filesystem-ssh2.php put_contents fails

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

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

Download all attachments as: .zip

Change History (8)

comment:1 lostinlafayette5 years ago

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.

comment:2 lostinlafayette5 years ago

I missed an equal sign, should be ===

comment:3 ShaneF5 years ago

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

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

dd325 years ago

props lostinlafayette

comment:5 lostinlafayette5 years ago

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

comment:6 dd325 years ago

  • Keywords commit added; needs-testing removed

comment:7 azaozz5 years ago

  • 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.