From 84f94fdfd2f6eae5422d3f26b0529b413ef7f49b Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 30 Oct 2012 04:04:05 -0700 Subject: [PATCH] [FileBackend] Avoid some stat calls in various operations. * copy() and rename() will overwrite any destination, including on Windows. Tested with Windows 7, and even rename() does this. The /Y flag is also set for Windows cmd commands now. * Set the "binary mode" /B flag for Windows cmd commands. Change-Id: Id11f31b020f786d5b66b0c57298ecc2b9d6170fb --- includes/filebackend/FSFileBackend.php | 50 ++++++-------------------- 1 file changed, 10 insertions(+), 40 deletions(-) diff --git a/includes/filebackend/FSFileBackend.php b/includes/filebackend/FSFileBackend.php index 04cf29edaf..3a03d4d12b 100644 --- a/includes/filebackend/FSFileBackend.php +++ b/includes/filebackend/FSFileBackend.php @@ -190,16 +190,9 @@ class FSFileBackend extends FileBackendStore { return $status; } - if ( file_exists( $dest ) ) { - $ok = unlink( $dest ); - if ( !$ok ) { - $status->fatal( 'backend-fail-delete', $params['dst'] ); - return $status; - } - } - if ( !empty( $params['async'] ) ) { // deferred - $cmd = implode( ' ', array( wfIsWindows() ? 'COPY' : 'cp', + $cmd = implode( ' ', array( + wfIsWindows() ? 'COPY /B /Y' : 'cp', // (binary, overwrite) wfEscapeShellArg( $this->cleanPathSlashes( $params['src'] ) ), wfEscapeShellArg( $this->cleanPathSlashes( $dest ) ) ) ); @@ -257,16 +250,9 @@ class FSFileBackend extends FileBackendStore { return $status; // do nothing; either OK or bad status } - if ( file_exists( $dest ) ) { - $ok = unlink( $dest ); - if ( !$ok ) { - $status->fatal( 'backend-fail-delete', $params['dst'] ); - return $status; - } - } - if ( !empty( $params['async'] ) ) { // deferred - $cmd = implode( ' ', array( wfIsWindows() ? 'COPY' : 'cp', + $cmd = implode( ' ', array( + wfIsWindows() ? 'COPY /B /Y' : 'cp', // (binary, overwrite) wfEscapeShellArg( $this->cleanPathSlashes( $source ) ), wfEscapeShellArg( $this->cleanPathSlashes( $dest ) ) ) ); @@ -324,19 +310,9 @@ class FSFileBackend extends FileBackendStore { return $status; // do nothing; either OK or bad status } - if ( file_exists( $dest ) ) { - // Windows does not support moving over existing files - if ( wfIsWindows() ) { - $ok = unlink( $dest ); - if ( !$ok ) { - $status->fatal( 'backend-fail-delete', $params['dst'] ); - return $status; - } - } - } - if ( !empty( $params['async'] ) ) { // deferred - $cmd = implode( ' ', array( wfIsWindows() ? 'MOVE' : 'mv', + $cmd = implode( ' ', array( + wfIsWindows() ? 'MOVE /Y' : 'mv', // (overwrite) wfEscapeShellArg( $this->cleanPathSlashes( $source ) ), wfEscapeShellArg( $this->cleanPathSlashes( $dest ) ) ) ); @@ -384,7 +360,8 @@ class FSFileBackend extends FileBackendStore { } if ( !empty( $params['async'] ) ) { // deferred - $cmd = implode( ' ', array( wfIsWindows() ? 'DEL' : 'unlink', + $cmd = implode( ' ', array( + wfIsWindows() ? 'DEL' : 'unlink', wfEscapeShellArg( $this->cleanPathSlashes( $source ) ) ) ); $status->value = new FSFileOpHandle( $this, $params, 'Copy', $cmd ); @@ -422,14 +399,6 @@ class FSFileBackend extends FileBackendStore { return $status; } - if ( file_exists( $dest ) ) { - $ok = unlink( $dest ); - if ( !$ok ) { - $status->fatal( 'backend-fail-delete', $params['dst'] ); - return $status; - } - } - if ( !empty( $params['async'] ) ) { // deferred $tempFile = TempFSFile::factory( 'create_', 'tmp' ); if ( !$tempFile ) { @@ -441,7 +410,8 @@ class FSFileBackend extends FileBackendStore { $status->fatal( 'backend-fail-create', $params['dst'] ); return $status; } - $cmd = implode( ' ', array( wfIsWindows() ? 'COPY' : 'cp', + $cmd = implode( ' ', array( + wfIsWindows() ? 'COPY /B /Y' : 'cp', // (binary, overwrite) wfEscapeShellArg( $this->cleanPathSlashes( $tempFile->getPath() ) ), wfEscapeShellArg( $this->cleanPathSlashes( $dest ) ) ) ); -- 2.20.1