Index: trunk/extensions/Deployment/includes/filesystems/FtpFilesystem.php |
— | — | @@ -488,8 +488,29 @@ |
489 | 489 | /** |
490 | 490 | * @see Filesystem::writeToFile |
491 | 491 | */ |
492 | | - public function writeToFile( $file, $contents ) { |
| 492 | + public function writeToFile( $file, $contents, $mode = false ) { |
| 493 | + $tempfile = wp_tempnam( $file ); |
| 494 | + $temp = fopen( $tempfile, 'w+' ); |
493 | 495 | |
| 496 | + if ( !$temp ) { |
| 497 | + return false; |
| 498 | + } |
| 499 | + |
| 500 | + fwrite( $temp, $contents ); |
| 501 | + |
| 502 | + // Skip back to the start of the file being written to |
| 503 | + fseek( $temp, 0 ); |
| 504 | + |
| 505 | + wfSuppressWarnings(); |
| 506 | + $ret = ftp_fput( $this->connection, $file, $temp, $this->isBinary( $contents ) ? FTP_BINARY : FTP_ASCII ); |
| 507 | + wfRestoreWarnings(); |
| 508 | + |
| 509 | + fclose( $temp ); |
| 510 | + unlink( $tempfile ); |
| 511 | + |
| 512 | + $this->chmod( $file, $mode ); |
| 513 | + |
| 514 | + return $ret; |
494 | 515 | } |
495 | 516 | |
496 | 517 | /** |
— | — | @@ -497,20 +518,23 @@ |
498 | 519 | */ |
499 | 520 | protected function parseListing( $line ) { |
500 | 521 | static $is_windows; |
501 | | - if ( is_null($is_windows) ) |
502 | | - $is_windows = stripos( ftp_systype($this->link), 'win') !== false; |
| 522 | + |
| 523 | + if ( is_null( $is_windows ) ) { |
| 524 | + $is_windows = stripos( ftp_systype( $this->connection ), 'win' ) !== false; |
| 525 | + } |
503 | 526 | |
504 | | - 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) ) { |
| 527 | + 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 ) ) { |
505 | 528 | $b = array(); |
506 | | - if ( $lucifer[3] < 70 ) |
507 | | - $lucifer[3] +=2000; |
508 | | - else |
509 | | - $lucifer[3] += 1900; // 4digit year fix |
510 | | - $b['isdir'] = ( $lucifer[7] == '<DIR>'); |
511 | | - if ( $b['isdir'] ) |
512 | | - $b['type'] = 'd'; |
513 | | - else |
514 | | - $b['type'] = 'f'; |
| 529 | + |
| 530 | + if ( $lucifer[3] < 70 ) { |
| 531 | + $lucifer[3] += 2000; |
| 532 | + } |
| 533 | + else { |
| 534 | + $lucifer[3] += 1900; // 4 digit year fix |
| 535 | + } |
| 536 | + |
| 537 | + $b['isdir'] = ( $lucifer[7] == '<DIR>' ); |
| 538 | + $b['type'] = $b['isdir'] ? 'd' : 'f'; |
515 | 539 | $b['size'] = $lucifer[7]; |
516 | 540 | $b['month'] = $lucifer[1]; |
517 | 541 | $b['day'] = $lucifer[2]; |
— | — | @@ -520,35 +544,46 @@ |
521 | 545 | $b['time'] = @mktime($lucifer[4] + (strcasecmp($lucifer[6], "PM") == 0 ? 12 : 0), $lucifer[5], 0, $lucifer[1], $lucifer[2], $lucifer[3]); |
522 | 546 | $b['am/pm'] = $lucifer[6]; |
523 | 547 | $b['name'] = $lucifer[8]; |
524 | | - } elseif ( !$is_windows && $lucifer = preg_split('/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY)) { |
| 548 | + } elseif ( !$is_windows && $lucifer = preg_split( '/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY ) ) { |
525 | 549 | //echo $line."\n"; |
| 550 | + |
526 | 551 | $lcount = count($lucifer); |
527 | | - if ( $lcount < 8 ) |
| 552 | + |
| 553 | + if ( $lcount < 8 ) { |
528 | 554 | return ''; |
| 555 | + } |
| 556 | + |
529 | 557 | $b = array(); |
530 | 558 | $b['isdir'] = $lucifer[0]{0} === 'd'; |
531 | 559 | $b['islink'] = $lucifer[0]{0} === 'l'; |
532 | | - if ( $b['isdir'] ) |
| 560 | + if ( $b['isdir'] ) { |
533 | 561 | $b['type'] = 'd'; |
534 | | - elseif ( $b['islink'] ) |
| 562 | + } |
| 563 | + elseif ( $b['islink'] ) { |
535 | 564 | $b['type'] = 'l'; |
536 | | - else |
| 565 | + } |
| 566 | + else { |
537 | 567 | $b['type'] = 'f'; |
| 568 | + } |
538 | 569 | $b['perms'] = $lucifer[0]; |
539 | 570 | $b['number'] = $lucifer[1]; |
540 | 571 | $b['owner'] = $lucifer[2]; |
541 | 572 | $b['group'] = $lucifer[3]; |
542 | 573 | $b['size'] = $lucifer[4]; |
| 574 | + |
543 | 575 | if ( $lcount == 8 ) { |
544 | | - sscanf($lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day']); |
545 | | - sscanf($lucifer[6], '%d:%d', $b['hour'], $b['minute']); |
546 | | - $b['time'] = @mktime($b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year']); |
| 576 | + sscanf( $lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day'] ); |
| 577 | + sscanf( $lucifer[6], '%d:%d', $b['hour'], $b['minute'] ); |
| 578 | + wfSuppressWarnings(); |
| 579 | + $b['time'] = mktime( $b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year'] ); |
| 580 | + wfRestoreWarnings(); |
547 | 581 | $b['name'] = $lucifer[7]; |
548 | 582 | } else { |
549 | 583 | $b['month'] = $lucifer[5]; |
550 | 584 | $b['day'] = $lucifer[6]; |
551 | | - if ( preg_match('/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2) ) { |
552 | | - $b['year'] = date("Y"); |
| 585 | + |
| 586 | + if ( preg_match( '/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2 ) ) { |
| 587 | + $b['year'] = date( 'Y' ); |
553 | 588 | $b['hour'] = $l2[1]; |
554 | 589 | $b['minute'] = $l2[2]; |
555 | 590 | } else { |
— | — | @@ -556,7 +591,8 @@ |
557 | 592 | $b['hour'] = 0; |
558 | 593 | $b['minute'] = 0; |
559 | 594 | } |
560 | | - $b['time'] = strtotime( sprintf('%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute']) ); |
| 595 | + |
| 596 | + $b['time'] = strtotime( sprintf( '%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute'] ) ); |
561 | 597 | $b['name'] = $lucifer[8]; |
562 | 598 | } |
563 | 599 | } |
Index: trunk/extensions/Deployment/includes/filesystems/DirectFilesystem.php |
— | — | @@ -472,8 +472,23 @@ |
473 | 473 | /** |
474 | 474 | * @see Filesystem::writeToFile |
475 | 475 | */ |
476 | | - public function writeToFile( $file, $contents ) { |
| 476 | + public function writeToFile( $file, $contents, $mode = false ) { |
| 477 | + wfSuppressWarnings(); |
| 478 | + $fopen = fopen( $file, 'w' ); |
| 479 | + wfRestoreWarnings(); |
477 | 480 | |
| 481 | + if ( !( $fp = $fopen ) ) { |
| 482 | + return false; |
| 483 | + } |
| 484 | + |
| 485 | + wfSuppressWarnings(); |
| 486 | + fwrite( $fp, $contents ); |
| 487 | + fclose( $fp ); |
| 488 | + wfRestoreWarnings(); |
| 489 | + |
| 490 | + $this->chmod( $file, $mode ); |
| 491 | + |
| 492 | + return true; |
478 | 493 | } |
479 | 494 | |
480 | 495 | } |
\ No newline at end of file |
Index: trunk/extensions/Deployment/includes/Filesystem.php |
— | — | @@ -53,12 +53,13 @@ |
54 | 54 | /** |
55 | 55 | * Writes a string to a file. |
56 | 56 | * |
57 | | - * @param string $file Path to the file. |
58 | | - * @param string $contents |
| 57 | + * @param $file String: Path to the file. |
| 58 | + * @param $contents String |
| 59 | + * @param $mode Boolean |
59 | 60 | * |
60 | 61 | * @return boolean Success indicator |
61 | 62 | */ |
62 | | - public abstract function writeToFile( $file, $contents ); |
| 63 | + public abstract function writeToFile( $file, $contents, $mode = false ); |
63 | 64 | |
64 | 65 | /** |
65 | 66 | * Gets the current working directory. |
— | — | @@ -356,4 +357,15 @@ |
357 | 358 | wfDebug( $error ); |
358 | 359 | } |
359 | 360 | |
| 361 | + /** |
| 362 | + * Determines if the string provided contains binary characters. |
| 363 | + * |
| 364 | + * @param $text String: the contents to test against |
| 365 | + * |
| 366 | + * @return Boolean: true if string is binary, false otherwise |
| 367 | + */ |
| 368 | + protected function isBinary( $text ) { |
| 369 | + return (bool)preg_match( '|[^\x20-\x7E]|', $text ); // chr(32)..chr(127) |
| 370 | + } |
| 371 | + |
360 | 372 | } |
\ No newline at end of file |