Changeset 48089
- Timestamp:
- 06/19/2020 10:34:26 AM (5 years ago)
- Location:
- trunk/src/wp-admin/includes
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-filesystem-base.php
r47808 r48089 56 56 public function abspath() { 57 57 $folder = $this->find_folder( ABSPATH ); 58 58 59 // Perhaps the FTP folder is rooted at the WordPress install. 59 60 // Check for wp-includes folder in root. Could have some false positives, but rare. … … 61 62 $folder = '/'; 62 63 } 64 63 65 return $folder; 64 66 } … … 189 191 continue; 190 192 } 193 191 194 if ( $folder === $dir ) { 192 195 return trailingslashit( constant( $constant ) ); … … 199 202 continue; 200 203 } 204 201 205 if ( 0 === stripos( $folder, $dir ) ) { // $folder starts with $dir. 202 206 $potential_folder = preg_replace( '#^' . preg_quote( $dir, '#' ) . '/#i', trailingslashit( constant( $constant ) ), $folder ); … … 205 209 if ( $this->is_dir( $potential_folder ) ) { 206 210 $this->cache[ $folder ] = $potential_folder; 211 207 212 return $potential_folder; 208 213 } … … 211 216 } elseif ( 'direct' === $this->method ) { 212 217 $folder = str_replace( '\\', '/', $folder ); // Windows path sanitisation. 218 213 219 return trailingslashit( $folder ); 214 220 } … … 224 230 $folder = trailingslashit( $folder ); 225 231 $this->cache[ $folder ] = $folder; 232 226 233 return $folder; 227 234 } 235 228 236 $return = $this->search_for_folder( $folder ); 237 229 238 if ( $return ) { 230 239 $this->cache[ $folder ] = $return; 231 240 } 241 232 242 return $return; 233 243 } … … 280 290 // Let's try that folder: 281 291 $newdir = trailingslashit( path_join( $base, $key ) ); 292 282 293 if ( $this->verbose ) { 283 294 /* translators: %s: Directory name. */ … … 288 299 $newfolder = implode( '/', array_slice( $folder_parts, $index + 1 ) ); 289 300 $ret = $this->search_for_folder( $newfolder, $newdir, $loop ); 301 290 302 if ( $ret ) { 291 303 return $ret; … … 301 313 printf( "\n" . __( 'Found %s' ) . "<br/>\n", $base . $last_path ); 302 314 } 315 303 316 return trailingslashit( $base . $last_path ); 304 317 } … … 330 343 public function gethchmod( $file ) { 331 344 $perms = intval( $this->getchmod( $file ), 8 ); 345 332 346 if ( ( $perms & 0xC000 ) == 0xC000 ) { // Socket. 333 347 $info = 's'; … … 368 382 ( ( $perms & 0x0200 ) ? 't' : 'x' ) : 369 383 ( ( $perms & 0x0200 ) ? 'T' : '-' ) ); 384 370 385 return $info; 371 386 } … … 403 418 for ( $i = 0, $c = count( $attarray ); $i < $c; $i++ ) { 404 419 $key = array_search( $attarray[ $i ], $legal, true ); 420 405 421 if ( $key ) { 406 422 $realmode .= $legal[ $key ]; … … 421 437 $newmode .= $mode[4] + $mode[5] + $mode[6]; 422 438 $newmode .= $mode[7] + $mode[8] + $mode[9]; 439 423 440 return $newmode; 424 441 } -
trunk/src/wp-admin/includes/class-wp-filesystem-direct.php
r48031 r48089 65 65 public function put_contents( $file, $contents, $mode = false ) { 66 66 $fp = @fopen( $file, 'wb' ); 67 67 68 if ( ! $fp ) { 68 69 return false; … … 126 127 return false; 127 128 } 129 128 130 if ( ! $recursive ) { 129 131 return chgrp( $file, $group ); 130 132 } 133 131 134 if ( ! $this->is_dir( $file ) ) { 132 135 return chgrp( $file, $group ); 133 136 } 137 134 138 // Is a directory, and we want recursive. 135 139 $file = trailingslashit( $file ); 136 140 $filelist = $this->dirlist( $file ); 141 137 142 foreach ( $filelist as $filename ) { 138 143 $this->chgrp( $file . $filename, $group, $recursive ); … … 168 173 return chmod( $file, $mode ); 169 174 } 175 170 176 // Is a directory, and we want recursive. 171 177 $file = trailingslashit( $file ); 172 178 $filelist = $this->dirlist( $file ); 179 173 180 foreach ( (array) $filelist as $filename => $filemeta ) { 174 181 $this->chmod( $file . $filename, $mode, $recursive ); … … 193 200 return false; 194 201 } 202 195 203 if ( ! $recursive ) { 196 204 return chown( $file, $owner ); 197 205 } 206 198 207 if ( ! $this->is_dir( $file ) ) { 199 208 return chown( $file, $owner ); 200 209 } 210 201 211 // Is a directory, and we want recursive. 202 212 $filelist = $this->dirlist( $file ); 213 203 214 foreach ( $filelist as $filename ) { 204 215 $this->chown( $file . '/' . $filename, $owner, $recursive ); 205 216 } 217 206 218 return true; 207 219 } … … 217 229 public function owner( $file ) { 218 230 $owneruid = @fileowner( $file ); 231 219 232 if ( ! $owneruid ) { 220 233 return false; 221 234 } 235 222 236 if ( ! function_exists( 'posix_getpwuid' ) ) { 223 237 return $owneruid; 224 238 } 239 225 240 $ownerarray = posix_getpwuid( $owneruid ); 241 226 242 if ( ! $ownerarray ) { 227 243 return false; 228 244 } 245 229 246 return $ownerarray['name']; 230 247 } … … 254 271 public function group( $file ) { 255 272 $gid = @filegroup( $file ); 273 256 274 if ( ! $gid ) { 257 275 return false; 258 276 } 277 259 278 if ( ! function_exists( 'posix_getgrgid' ) ) { 260 279 return $gid; 261 280 } 281 262 282 $grouparray = posix_getgrgid( $gid ); 283 263 284 if ( ! $grouparray ) { 264 285 return false; 265 286 } 287 266 288 return $grouparray['name']; 267 289 } … … 286 308 287 309 $rtval = copy( $source, $destination ); 310 288 311 if ( $mode ) { 289 312 $this->chmod( $destination, $mode ); 290 313 } 314 291 315 return $rtval; 292 316 } … … 315 339 if ( $this->copy( $source, $destination, $overwrite ) && $this->exists( $destination ) ) { 316 340 $this->delete( $source ); 341 317 342 return true; 318 343 } else { … … 338 363 return false; 339 364 } 365 340 366 $file = str_replace( '\\', '/', $file ); // For Win32, occasional problems deleting files otherwise. 341 367 … … 343 369 return @unlink( $file ); 344 370 } 371 345 372 if ( ! $recursive && $this->is_dir( $file ) ) { 346 373 return @rmdir( $file ); … … 352 379 353 380 $retval = true; 381 354 382 if ( is_array( $filelist ) ) { 355 383 foreach ( $filelist as $filename => $fileinfo ) { … … 481 509 $time = time(); 482 510 } 511 483 512 if ( 0 == $atime ) { 484 513 $atime = time(); 485 514 } 515 486 516 return touch( $file, $time, $atime ); 487 517 } … … 504 534 // Safe mode fails with a trailing slash under certain PHP versions. 505 535 $path = untrailingslashit( $path ); 536 506 537 if ( empty( $path ) ) { 507 538 return false; … … 515 546 return false; 516 547 } 548 517 549 $this->chmod( $path, $chmod ); 550 518 551 if ( $chown ) { 519 552 $this->chown( $path, $chown ); 520 553 } 554 521 555 if ( $chgrp ) { 522 556 $this->chgrp( $path, $chgrp ); 523 557 } 558 524 559 return true; 525 560 } … … 577 612 578 613 $dir = dir( $path ); 614 579 615 if ( ! $dir ) { 580 616 return false; … … 620 656 $ret[ $struc['name'] ] = $struc; 621 657 } 658 622 659 $dir->close(); 623 660 unset( $dir ); 661 624 662 return $ret; 625 663 } -
trunk/src/wp-admin/includes/class-wp-filesystem-ftpext.php
r47808 r48089 70 70 71 71 $this->options['ssl'] = false; 72 72 73 if ( isset( $opt['connection_type'] ) && 'ftps' === $opt['connection_type'] ) { 73 74 $this->options['ssl'] = true; … … 98 99 ) 99 100 ); 101 100 102 return false; 101 103 } … … 110 112 ) 111 113 ); 114 112 115 return false; 113 116 } … … 115 118 // Set the connection to use Passive FTP. 116 119 ftp_pasv( $this->link, true ); 120 117 121 if ( @ftp_get_option( $this->link, FTP_TIMEOUT_SEC ) < FS_TIMEOUT ) { 118 122 @ftp_set_option( $this->link, FTP_TIMEOUT_SEC, FS_TIMEOUT ); … … 132 136 */ 133 137 public function get_contents( $file ) { 134 $tempfile = wp_tempnam( $file );135 $temp 136 137 if ( ! $temp ) {138 $tempfile = wp_tempnam( $file ); 139 $temphandle = fopen( $tempfile, 'w+' ); 140 141 if ( ! $temphandle ) { 138 142 unlink( $tempfile ); 139 143 return false; 140 144 } 141 145 142 if ( ! ftp_fget( $this->link, $temp , $file, FTP_BINARY ) ) {143 fclose( $temp );146 if ( ! ftp_fget( $this->link, $temphandle, $file, FTP_BINARY ) ) { 147 fclose( $temphandle ); 144 148 unlink( $tempfile ); 145 149 return false; 146 150 } 147 151 148 fseek( $temp , 0 ); // Skip back to the start of the file being written to.152 fseek( $temphandle, 0 ); // Skip back to the start of the file being written to. 149 153 $contents = ''; 150 154 151 while ( ! feof( $temp ) ) {152 $contents .= fread( $temp , 8 * KB_IN_BYTES );153 } 154 155 fclose( $temp );155 while ( ! feof( $temphandle ) ) { 156 $contents .= fread( $temphandle, 8 * KB_IN_BYTES ); 157 } 158 159 fclose( $temphangle ); 156 160 unlink( $tempfile ); 161 157 162 return $contents; 158 163 } … … 182 187 */ 183 188 public function put_contents( $file, $contents, $mode = false ) { 184 $tempfile = wp_tempnam( $file );185 $temp 186 187 if ( ! $temp ) {189 $tempfile = wp_tempnam( $file ); 190 $temphandle = fopen( $tempfile, 'wb+' ); 191 192 if ( ! $temphandle ) { 188 193 unlink( $tempfile ); 189 194 return false; … … 193 198 194 199 $data_length = strlen( $contents ); 195 $bytes_written = fwrite( $temp , $contents );200 $bytes_written = fwrite( $temphandle, $contents ); 196 201 197 202 reset_mbstring_encoding(); 198 203 199 204 if ( $data_length !== $bytes_written ) { 200 fclose( $temp );205 fclose( $temphandle ); 201 206 unlink( $tempfile ); 202 207 return false; 203 208 } 204 209 205 fseek( $temp , 0 ); // Skip back to the start of the file being written to.206 207 $ret = ftp_fput( $this->link, $file, $temp , FTP_BINARY );208 209 fclose( $temp );210 fseek( $temphandle, 0 ); // Skip back to the start of the file being written to. 211 212 $ret = ftp_fput( $this->link, $file, $temphandle, FTP_BINARY ); 213 214 fclose( $temphandle ); 210 215 unlink( $tempfile ); 211 216 … … 224 229 public function cwd() { 225 230 $cwd = ftp_pwd( $this->link ); 231 226 232 if ( $cwd ) { 227 233 $cwd = trailingslashit( $cwd ); 228 234 } 235 229 236 return $cwd; 230 237 } … … 268 275 if ( $recursive && $this->is_dir( $file ) ) { 269 276 $filelist = $this->dirlist( $file ); 277 270 278 foreach ( (array) $filelist as $filename => $filemeta ) { 271 279 $this->chmod( $file . '/' . $filename, $mode, $recursive ); … … 277 285 return (bool) ftp_site( $this->link, sprintf( 'CHMOD %o %s', $mode, $file ) ); 278 286 } 287 279 288 return (bool) ftp_chmod( $this->link, $mode, $file ); 280 289 } … … 290 299 public function owner( $file ) { 291 300 $dir = $this->dirlist( $file ); 301 292 302 return $dir[ $file ]['owner']; 293 303 } … … 303 313 public function getchmod( $file ) { 304 314 $dir = $this->dirlist( $file ); 315 305 316 return $dir[ $file ]['permsn']; 306 317 } … … 316 327 public function group( $file ) { 317 328 $dir = $this->dirlist( $file ); 329 318 330 return $dir[ $file ]['group']; 319 331 } … … 336 348 return false; 337 349 } 350 338 351 $content = $this->get_contents( $source ); 352 339 353 if ( false === $content ) { 340 354 return false; 341 355 } 356 342 357 return $this->put_contents( $destination, $content, $mode ); 343 358 } … … 374 389 return false; 375 390 } 391 376 392 if ( 'f' === $type || $this->is_file( $file ) ) { 377 393 return ftp_delete( $this->link, $file ); 378 394 } 395 379 396 if ( ! $recursive ) { 380 397 return ftp_rmdir( $this->link, $file ); … … 382 399 383 400 $filelist = $this->dirlist( trailingslashit( $file ) ); 401 384 402 if ( ! empty( $filelist ) ) { 385 403 foreach ( $filelist as $delete_file ) { … … 387 405 } 388 406 } 407 389 408 return ftp_rmdir( $this->link, $file ); 390 409 } … … 431 450 $cwd = $this->cwd(); 432 451 $result = @ftp_chdir( $this->link, trailingslashit( $path ) ); 452 433 453 if ( $result && $path == $this->cwd() || $this->cwd() != $cwd ) { 434 454 @ftp_chdir( $this->link, $cwd ); 435 455 return true; 436 456 } 457 437 458 return false; 438 459 } … … 532 553 public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) { 533 554 $path = untrailingslashit( $path ); 555 534 556 if ( empty( $path ) ) { 535 557 return false; … … 539 561 return false; 540 562 } 563 541 564 $this->chmod( $path, $chmod ); 565 542 566 return true; 543 567 } … … 564 588 public function parselisting( $line ) { 565 589 static $is_windows = null; 590 566 591 if ( is_null( $is_windows ) ) { 567 592 $is_windows = stripos( ftp_systype( $this->link ), 'win' ) !== false; … … 570 595 if ( $is_windows && preg_match( '/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/', $line, $lucifer ) ) { 571 596 $b = array(); 597 572 598 if ( $lucifer[3] < 70 ) { 573 599 $lucifer[3] += 2000; … … 575 601 $lucifer[3] += 1900; // 4-digit year fix. 576 602 } 603 577 604 $b['isdir'] = ( '<DIR>' === $lucifer[7] ); 605 578 606 if ( $b['isdir'] ) { 579 607 $b['type'] = 'd'; … … 581 609 $b['type'] = 'f'; 582 610 } 611 583 612 $b['size'] = $lucifer[7]; 584 613 $b['month'] = $lucifer[1]; … … 592 621 } elseif ( ! $is_windows ) { 593 622 $lucifer = preg_split( '/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY ); 623 594 624 if ( $lucifer ) { 595 625 // echo $line."\n"; 596 626 $lcount = count( $lucifer ); 627 597 628 if ( $lcount < 8 ) { 598 629 return ''; 599 630 } 631 600 632 $b = array(); 601 633 $b['isdir'] = 'd' === $lucifer[0][0]; 602 634 $b['islink'] = 'l' === $lucifer[0][0]; 635 603 636 if ( $b['isdir'] ) { 604 637 $b['type'] = 'd'; … … 608 641 $b['type'] = 'f'; 609 642 } 643 610 644 $b['perms'] = $lucifer[0]; 611 645 $b['permsn'] = $this->getnumchmodfromh( $b['perms'] ); … … 614 648 $b['group'] = $lucifer[3]; 615 649 $b['size'] = $lucifer[4]; 650 616 651 if ( 8 == $lcount ) { 617 652 sscanf( $lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day'] ); 618 653 sscanf( $lucifer[6], '%d:%d', $b['hour'], $b['minute'] ); 654 619 655 $b['time'] = mktime( $b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year'] ); 620 656 $b['name'] = $lucifer[7]; … … 622 658 $b['month'] = $lucifer[5]; 623 659 $b['day'] = $lucifer[6]; 660 624 661 if ( preg_match( '/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2 ) ) { 625 662 $b['year'] = gmdate( 'Y' ); … … 631 668 $b['minute'] = 0; 632 669 } 670 633 671 $b['time'] = strtotime( sprintf( '%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute'] ) ); 634 672 $b['name'] = $lucifer[8]; … … 679 717 680 718 $pwd = ftp_pwd( $this->link ); 719 681 720 if ( ! @ftp_chdir( $this->link, $path ) ) { // Can't change to folder = folder doesn't exist. 682 721 return false; 683 722 } 723 684 724 $list = ftp_rawlist( $this->link, '-a', false ); 725 685 726 @ftp_chdir( $this->link, $pwd ); 686 727 … … 690 731 691 732 $dirlist = array(); 733 692 734 foreach ( $list as $k => $v ) { 693 735 $entry = $this->parselisting( $v ); 736 694 737 if ( empty( $entry ) ) { 695 738 continue; … … 712 755 713 756 $ret = array(); 757 714 758 foreach ( (array) $dirlist as $struc ) { 715 759 if ( 'd' === $struc['type'] ) { … … 723 767 $ret[ $struc['name'] ] = $struc; 724 768 } 769 725 770 return $ret; 726 771 } -
trunk/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php
r47808 r48089 37 37 return; 38 38 } 39 39 40 $this->ftp = new ftp(); 40 41 … … 88 89 ) 89 90 ); 91 90 92 return false; 91 93 } … … 100 102 ) 101 103 ); 104 102 105 return false; 103 106 } … … 112 115 ) 113 116 ); 117 114 118 return false; 115 119 } … … 118 122 $this->ftp->Passive( true ); 119 123 $this->ftp->setTimeout( FS_TIMEOUT ); 124 120 125 return true; 121 126 } … … 135 140 } 136 141 137 $temp = wp_tempnam( $file );138 139 $temphandle = fopen( $temp, 'w+' ); 142 $tempfile = wp_tempnam( $file ); 143 $temphandle = fopen( $tempfile, 'w+' ); 144 140 145 if ( ! $temphandle ) { 141 unlink( $temp );146 unlink( $tempfile ); 142 147 return false; 143 148 } … … 147 152 if ( ! $this->ftp->fget( $temphandle, $file ) ) { 148 153 fclose( $temphandle ); 149 unlink( $temp );154 unlink( $tempfile ); 150 155 151 156 reset_mbstring_encoding(); … … 164 169 165 170 fclose( $temphandle ); 166 unlink( $temp ); 171 unlink( $tempfile ); 172 167 173 return $contents; 168 174 } … … 192 198 */ 193 199 public function put_contents( $file, $contents, $mode = false ) { 194 $temp = wp_tempnam( $file ); 195 $temphandle = @fopen( $temp, 'w+' ); 200 $tempfile = wp_tempnam( $file ); 201 $temphandle = @fopen( $tempfile, 'w+' ); 202 196 203 if ( ! $temphandle ) { 197 unlink( $temp );204 unlink( $tempfile ); 198 205 return false; 199 206 } … … 203 210 204 211 $bytes_written = fwrite( $temphandle, $contents ); 212 205 213 if ( false === $bytes_written || strlen( $contents ) != $bytes_written ) { 206 214 fclose( $temphandle ); 207 unlink( $temp );215 unlink( $tempfile ); 208 216 209 217 reset_mbstring_encoding(); … … 219 227 220 228 fclose( $temphandle ); 221 unlink( $temp );229 unlink( $tempfile ); 222 230 223 231 $this->chmod( $file, $mode ); … … 235 243 public function cwd() { 236 244 $cwd = $this->ftp->pwd(); 245 237 246 if ( $cwd ) { 238 247 $cwd = trailingslashit( $cwd ); 239 248 } 249 240 250 return $cwd; 241 251 } … … 279 289 if ( $recursive && $this->is_dir( $file ) ) { 280 290 $filelist = $this->dirlist( $file ); 291 281 292 foreach ( (array) $filelist as $filename => $filemeta ) { 282 293 $this->chmod( $file . '/' . $filename, $mode, $recursive ); … … 298 309 public function owner( $file ) { 299 310 $dir = $this->dirlist( $file ); 311 300 312 return $dir[ $file ]['owner']; 301 313 } … … 311 323 public function getchmod( $file ) { 312 324 $dir = $this->dirlist( $file ); 325 313 326 return $dir[ $file ]['permsn']; 314 327 } … … 324 337 public function group( $file ) { 325 338 $dir = $this->dirlist( $file ); 339 326 340 return $dir[ $file ]['group']; 327 341 } … … 346 360 347 361 $content = $this->get_contents( $source ); 362 348 363 if ( false === $content ) { 349 364 return false; … … 384 399 return false; 385 400 } 401 386 402 if ( 'f' === $type || $this->is_file( $file ) ) { 387 403 return $this->ftp->delete( $file ); 388 404 } 405 389 406 if ( ! $recursive ) { 390 407 return $this->ftp->rmdir( $file ); … … 425 442 return false; 426 443 } 444 427 445 if ( $this->exists( $file ) ) { 428 446 return true; 429 447 } 448 430 449 return false; 431 450 } … … 441 460 public function is_dir( $path ) { 442 461 $cwd = $this->cwd(); 462 443 463 if ( $this->chdir( $path ) ) { 444 464 $this->chdir( $cwd ); 445 465 return true; 446 466 } 467 447 468 return false; 448 469 } … … 542 563 public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) { 543 564 $path = untrailingslashit( $path ); 565 544 566 if ( empty( $path ) ) { 545 567 return false; … … 549 571 return false; 550 572 } 573 551 574 if ( ! $chmod ) { 552 575 $chmod = FS_CHMOD_DIR; 553 576 } 577 554 578 $this->chmod( $path, $chmod ); 579 555 580 return true; 556 581 } … … 606 631 607 632 $list = $this->ftp->dirlist( $path ); 633 608 634 if ( empty( $list ) && ! $this->exists( $path ) ) { 609 635 … … 614 640 615 641 $ret = array(); 642 616 643 foreach ( $list as $struc ) { 617 644 -
trunk/src/wp-admin/includes/class-wp-filesystem-ssh2.php
r48031 r48089 133 133 ) 134 134 ); 135 135 136 return false; 136 137 } … … 146 147 ) 147 148 ); 149 148 150 return false; 149 151 } … … 158 160 ) 159 161 ); 162 160 163 return false; 161 164 } … … 163 166 164 167 $this->sftp_link = ssh2_sftp( $this->link ); 168 165 169 if ( ! $this->sftp_link ) { 166 170 $this->errors->add( … … 172 176 ) 173 177 ); 178 174 179 return false; 175 180 } … … 195 200 $path = '/./'; 196 201 } 202 197 203 return 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $path, '/' ); 198 204 } … … 212 218 213 219 $stream = ssh2_exec( $this->link, $command ); 220 214 221 if ( ! $stream ) { 215 222 $this->errors->add( … … 233 240 } 234 241 } 242 235 243 return false; 236 244 } … … 293 301 public function cwd() { 294 302 $cwd = ssh2_sftp_realpath( $this->sftp_link, '.' ); 303 295 304 if ( $cwd ) { 296 305 $cwd = trailingslashit( trim( $cwd ) ); 297 306 } 307 298 308 return $cwd; 299 309 } … … 326 336 return false; 327 337 } 338 328 339 if ( ! $recursive || ! $this->is_dir( $file ) ) { 329 340 return $this->run_command( sprintf( 'chgrp %s %s', escapeshellarg( $group ), escapeshellarg( $file ) ), true ); 330 341 } 342 331 343 return $this->run_command( sprintf( 'chgrp -R %s %s', escapeshellarg( $group ), escapeshellarg( $file ) ), true ); 332 344 } … … 362 374 return $this->run_command( sprintf( 'chmod %o %s', $mode, escapeshellarg( $file ) ), true ); 363 375 } 376 364 377 return $this->run_command( sprintf( 'chmod -R %o %s', $mode, escapeshellarg( $file ) ), true ); 365 378 } … … 380 393 return false; 381 394 } 395 382 396 if ( ! $recursive || ! $this->is_dir( $file ) ) { 383 397 return $this->run_command( sprintf( 'chown %s %s', escapeshellarg( $owner ), escapeshellarg( $file ) ), true ); 384 398 } 399 385 400 return $this->run_command( sprintf( 'chown -R %s %s', escapeshellarg( $owner ), escapeshellarg( $file ) ), true ); 386 401 } … … 396 411 public function owner( $file ) { 397 412 $owneruid = @fileowner( $this->sftp_path( $file ) ); 413 398 414 if ( ! $owneruid ) { 399 415 return false; 400 416 } 417 401 418 if ( ! function_exists( 'posix_getpwuid' ) ) { 402 419 return $owneruid; 403 420 } 421 404 422 $ownerarray = posix_getpwuid( $owneruid ); 423 405 424 if ( ! $ownerarray ) { 406 425 return false; 407 426 } 427 408 428 return $ownerarray['name']; 409 429 } … … 431 451 public function group( $file ) { 432 452 $gid = @filegroup( $this->sftp_path( $file ) ); 453 433 454 if ( ! $gid ) { 434 455 return false; 435 456 } 457 436 458 if ( ! function_exists( 'posix_getgrgid' ) ) { 437 459 return $gid; 438 460 } 461 439 462 $grouparray = posix_getgrgid( $gid ); 463 440 464 if ( ! $grouparray ) { 441 465 return false; 442 466 } 467 443 468 return $grouparray['name']; 444 469 } … … 461 486 return false; 462 487 } 488 463 489 $content = $this->get_contents( $source ); 490 464 491 if ( false === $content ) { 465 492 return false; 466 493 } 494 467 495 return $this->put_contents( $destination, $content, $mode ); 468 496 } … … 509 537 return ssh2_sftp_unlink( $this->sftp_link, $file ); 510 538 } 539 511 540 if ( ! $recursive ) { 512 541 return ssh2_sftp_rmdir( $this->sftp_link, $file ); 513 542 } 543 514 544 $filelist = $this->dirlist( $file ); 545 515 546 if ( is_array( $filelist ) ) { 516 547 foreach ( $filelist as $filename => $fileinfo ) { … … 518 549 } 519 550 } 551 520 552 return ssh2_sftp_rmdir( $this->sftp_link, $file ); 521 553 } … … 651 683 public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) { 652 684 $path = untrailingslashit( $path ); 685 653 686 if ( empty( $path ) ) { 654 687 return false; … … 658 691 $chmod = FS_CHMOD_DIR; 659 692 } 693 660 694 if ( ! ssh2_sftp_mkdir( $this->sftp_link, $path, $chmod, true ) ) { 661 695 return false; 662 696 } 697 663 698 if ( $chown ) { 664 699 $this->chown( $path, $chown ); 665 700 } 701 666 702 if ( $chgrp ) { 667 703 $this->chgrp( $path, $chgrp ); 668 704 } 705 669 706 return true; 670 707 } … … 765 802 $ret[ $struc['name'] ] = $struc; 766 803 } 804 767 805 $dir->close(); 768 806 unset( $dir ); 807 769 808 return $ret; 770 809 }
Note: See TracChangeset
for help on using the changeset viewer.