X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/wordpress.git/blobdiff_plain/b3ddbea8a296025a672b3c3ddca158dc51ed8080..888fa4ed68091f3314f711c5f6fe75858bf5410b:/wp-admin/includes/class-wp-filesystem-ssh2.php diff --git a/wp-admin/includes/class-wp-filesystem-ssh2.php b/wp-admin/includes/class-wp-filesystem-ssh2.php index b809f455..30a96b1d 100644 --- a/wp-admin/includes/class-wp-filesystem-ssh2.php +++ b/wp-admin/includes/class-wp-filesystem-ssh2.php @@ -1,13 +1,6 @@ sftp_link . '/' . $file); } @@ -161,12 +154,14 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base { } function put_contents($file, $contents, $mode = false ) { - $file = ltrim($file, '/'); - $ret = file_put_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file, $contents); + $ret = file_put_contents( 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $file, '/' ), $contents ); + + if ( $ret !== strlen( $contents ) ) + return false; $this->chmod($file, $mode); - return false !== $ret; + return true; } function cwd() { @@ -184,8 +179,8 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base { if ( ! $this->exists($file) ) return false; if ( ! $recursive || ! $this->is_dir($file) ) - return $this->run_command(sprintf('chgrp %o %s', $mode, escapeshellarg($file)), true); - return $this->run_command(sprintf('chgrp -R %o %s', $mode, escapeshellarg($file)), true); + return $this->run_command(sprintf('chgrp %s %s', escapeshellarg($group), escapeshellarg($file)), true); + return $this->run_command(sprintf('chgrp -R %s %s', escapeshellarg($group), escapeshellarg($file)), true); } function chmod($file, $mode = false, $recursive = false) { @@ -206,12 +201,22 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base { return $this->run_command(sprintf('chmod -R %o %s', $mode, escapeshellarg($file)), true); } - function chown($file, $owner, $recursive = false ) { + /** + * Change the ownership of a file / folder. + * + * @since Unknown + * + * @param string $file Path to the file. + * @param mixed $owner A user name or number. + * @param bool $recursive Optional. If set True changes file owner recursivly. Defaults to False. + * @return bool Returns true on success or false on failure. + */ + function chown( $file, $owner, $recursive = false ) { if ( ! $this->exists($file) ) return false; if ( ! $recursive || ! $this->is_dir($file) ) - return $this->run_command(sprintf('chown %o %s', $mode, escapeshellarg($file)), true); - return $this->run_command(sprintf('chown -R %o %s', $mode, escapeshellarg($file)), true); + return $this->run_command(sprintf('chown %s %s', escapeshellarg($owner), escapeshellarg($file)), true); + return $this->run_command(sprintf('chown -R %s %s', escapeshellarg($owner), escapeshellarg($file)), true); } function owner($file) { @@ -225,7 +230,7 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base { } function getchmod($file) { - return substr(decoct(@fileperms( 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim($file, '/') )),3); + return substr( decoct( @fileperms( 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $file, '/' ) ) ), -3 ); } function group($file) { @@ -306,11 +311,14 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base { } function touch($file, $time = 0, $atime = 0) { - //Not implmented. + //Not implemented. } function mkdir($path, $chmod = false, $chown = false, $chgrp = false) { $path = untrailingslashit($path); + if ( empty($path) ) + return false; + if ( ! $chmod ) $chmod = FS_CHMOD_DIR; if ( ! ssh2_sftp_mkdir($this->sftp_link, $path, $chmod, true) )