Changeset 34738
- Timestamp:
- 10/01/2015 05:39:44 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-filesystem-ssh2.php
r33984 r34738 137 137 138 138 /** 139 * Gets the ssh2.sftp PHP stream wrapper path to open for the given file. 140 * 141 * This method also works around a PHP bug where the root directory (/) cannot 142 * be opened by PHP functions, causing a false failure. In order to work around 143 * this, the path is converted to /./ which is semantically the same as / 144 * See https://bugs.php.net/bug.php?id=64169 for more details. 145 * 146 * @access public 147 * 148 * @since 4.4 149 * 150 * @param string $path The File/Directory path on the remote server to return 151 * @return string The ssh2.sftp:// wrapped path to use. 152 */ 153 public function sftp_path( $path ) { 154 if ( '/' === $path ) { 155 $path = '/./'; 156 } 157 return 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $path, '/' ); 158 } 159 160 /** 139 161 * @access public 140 162 * … … 170 192 */ 171 193 public function get_contents( $file ) { 172 $file = ltrim($file, '/'); 173 return file_get_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file); 194 return file_get_contents( $this->sftp_path( $file ) ); 174 195 } 175 196 … … 181 202 */ 182 203 public function get_contents_array($file) { 183 $file = ltrim($file, '/'); 184 return file('ssh2.sftp://' . $this->sftp_link . '/' . $file); 204 return file( $this->sftp_path( $file ) ); 185 205 } 186 206 … … 194 214 */ 195 215 public function put_contents($file, $contents, $mode = false ) { 196 $ret = file_put_contents( 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $file, '/'), $contents );216 $ret = file_put_contents( $this->sftp_path( $file ), $contents ); 197 217 198 218 if ( $ret !== strlen( $contents ) ) … … 295 315 */ 296 316 public function owner($file) { 297 $owneruid = @fileowner( 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim($file, '/'));317 $owneruid = @fileowner( $this->sftp_path( $file ) ); 298 318 if ( ! $owneruid ) 299 319 return false; … … 311 331 */ 312 332 public function getchmod($file) { 313 return substr( decoct( @fileperms( 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $file, '/') ) ), -3 );333 return substr( decoct( @fileperms( $this->sftp_path( $file ) ) ), -3 ); 314 334 } 315 335 … … 321 341 */ 322 342 public function group($file) { 323 $gid = @filegroup( 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim($file, '/'));343 $gid = @filegroup( $this->sftp_path( $file ) ); 324 344 if ( ! $gid ) 325 345 return false; … … 389 409 */ 390 410 public function exists($file) { 391 $file = ltrim($file, '/'); 392 return file_exists('ssh2.sftp://' . $this->sftp_link . '/' . $file); 411 return file_exists( $this->sftp_path( $file ) ); 393 412 } 394 413 … … 400 419 */ 401 420 public function is_file($file) { 402 $file = ltrim($file, '/'); 403 return is_file('ssh2.sftp://' . $this->sftp_link . '/' . $file); 421 return is_file( $this->sftp_path( $file ) ); 404 422 } 405 423 … … 411 429 */ 412 430 public function is_dir($path) { 413 $path = ltrim($path, '/'); 414 return is_dir('ssh2.sftp://' . $this->sftp_link . '/' . $path); 431 return is_dir( $this->sftp_path( $path ) ); 415 432 } 416 433 … … 422 439 */ 423 440 public function is_readable($file) { 424 $file = ltrim($file, '/'); 425 return is_readable('ssh2.sftp://' . $this->sftp_link . '/' . $file); 441 return is_readable( $this->sftp_path( $file ) ); 426 442 } 427 443 … … 444 460 */ 445 461 public function atime($file) { 446 $file = ltrim($file, '/'); 447 return fileatime('ssh2.sftp://' . $this->sftp_link . '/' . $file); 462 return fileatime( $this->sftp_path( $file ) ); 448 463 } 449 464 … … 455 470 */ 456 471 public function mtime($file) { 457 $file = ltrim($file, '/'); 458 return filemtime('ssh2.sftp://' . $this->sftp_link . '/' . $file); 472 return filemtime( $this->sftp_path( $file ) ); 459 473 } 460 474 … … 466 480 */ 467 481 public function size($file) { 468 $file = ltrim($file, '/'); 469 return filesize('ssh2.sftp://' . $this->sftp_link . '/' . $file); 482 return filesize( $this->sftp_path( $file ) ); 470 483 } 471 484 … … 537 550 538 551 $ret = array(); 539 $dir = @dir( 'ssh2.sftp://' . $this->sftp_link .'/' . ltrim($path, '/') );552 $dir = @dir( $this->sftp_path( $path ) ); 540 553 541 554 if ( ! $dir )
Note: See TracChangeset
for help on using the changeset viewer.