* Likewise, error suppression should be used to avoid path disclosure.
*
* @ingroup FileBackend
+ * @since 1.19
*/
class FSFileBackend extends FileBackend {
protected $basePath; // string; directory holding the container directories
$status->fatal( 'backend-fail-alreadyexists', $params['dst'] );
return $status;
}
- } else {
- if ( !wfMkdirParents( dirname( $dest ) ) ) {
- $status->fatal( 'directorycreateerror', $params['dst'] );
- return $status;
- }
}
wfSuppressWarnings();
$ok = copy( $params['src'], $dest );
wfRestoreWarnings();
if ( !$ok ) {
- $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] );
+ $status->fatal( 'backend-fail-store', $params['src'], $params['dst'] );
return $status;
}
$status->fatal( 'backend-fail-alreadyexists', $params['dst'] );
return $status;
}
- } else {
- if ( !wfMkdirParents( dirname( $dest ) ) ) {
- $status->fatal( 'directorycreateerror', $params['dst'] );
- return $status;
- }
}
wfSuppressWarnings();
$status->fatal( 'backend-fail-alreadyexists', $params['dst'] );
return $status;
}
- } else {
- if ( !wfMkdirParents( dirname( $dest ) ) ) {
- $status->fatal( 'directorycreateerror', $params['dst'] );
- return $status;
- }
}
wfSuppressWarnings();
$status->fatal( 'backend-fail-alreadyexists', $params['dst'] );
return $status;
}
- } else {
- if ( !wfMkdirParents( dirname( $dest ) ) ) {
- $status->fatal( 'directorycreateerror', $params['dst'] );
- return $status;
- }
}
wfSuppressWarnings();
list( $b, $shortCont, $r ) = FileBackend::splitStoragePath( $params['dir'] );
$contRoot = $this->containerFSRoot( $shortCont, $fullCont ); // must be valid
$dir = ( $dirRel != '' ) ? "{$contRoot}/{$dirRel}" : $contRoot;
- if ( !wfMkdirParents( $dir ) ) {
+ if ( !wfMkdirParents( $dir ) ) { // make directory and its parents
$status->fatal( 'directorycreateerror', $params['dir'] );
} elseif ( !is_writable( $dir ) ) {
$status->fatal( 'directoryreadonlyerror', $params['dir'] );
list( $b, $shortCont, $r ) = FileBackend::splitStoragePath( $params['dir'] );
$contRoot = $this->containerFSRoot( $shortCont, $fullCont ); // must be valid
$dir = ( $dirRel != '' ) ? "{$contRoot}/{$dirRel}" : $contRoot;
- if ( !wfMkdirParents( $dir ) ) {
- $status->fatal( 'directorycreateerror', $params['dir'] );
- return $status;
- }
// Seed new directories with a blank index.html, to prevent crawling...
if ( !empty( $params['noListing'] ) && !file_exists( "{$dir}/index.html" ) ) {
wfSuppressWarnings();
/**
* Wrapper around RecursiveDirectoryIterator that catches
* exception or does any custom behavoir that we may want.
+ * Do not use this class from places outside FSFileBackend.
*
* @ingroup FileBackend
*/
function doTestStore( $op, $source, $dest ) {
$backendName = $this->backendClass();
+ $this->backend->prepare( array( 'dir' => dirname( $dest ) ) );
+
file_put_contents( $source, "Unit test file" );
$status = $this->backend->doOperation( $op );
function doTestCopy( $op, $source, $dest ) {
$backendName = $this->backendClass();
+ $this->backend->prepare( array( 'dir' => dirname( $source ) ) );
+ $this->backend->prepare( array( 'dir' => dirname( $dest ) ) );
+
$status = $this->backend->doOperation(
array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
$this->assertEquals( true, $status->isOK(),
public function doTestMove( $op, $source, $dest ) {
$backendName = $this->backendClass();
+ $this->backend->prepare( array( 'dir' => dirname( $source ) ) );
+ $this->backend->prepare( array( 'dir' => dirname( $dest ) ) );
+
$status = $this->backend->doOperation(
array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
$this->assertEquals( true, $status->isOK(),
public function doTestDelete( $op, $source, $withSource, $okStatus ) {
$backendName = $this->backendClass();
+ $this->backend->prepare( array( 'dir' => dirname( $source ) ) );
+
if ( $withSource ) {
$status = $this->backend->doOperation(
array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
public function doTestCreate( $op, $dest, $alreadyExists, $okStatus, $newSize ) {
$backendName = $this->backendClass();
+ $this->backend->prepare( array( 'dir' => dirname( $dest ) ) );
+
$oldText = 'blah...blah...waahwaah';
if ( $alreadyExists ) {
$status = $this->backend->doOperation(
// Create sources
$ops = array();
foreach ( $srcs as $i => $source ) {
+ $this->backend->prepare( array( 'dir' => dirname( $source ) ) );
$ops[] = array(
'op' => 'create', // operation
'dst' => $source, // source
/**
* @dataProvider provider_testGetFileContents
*/
- public function doTestGetFileContents( $src, $content ) {
+ public function doTestGetFileContents( $source, $content ) {
$backendName = $this->backendClass();
+ $this->backend->prepare( array( 'dir' => dirname( $source ) ) );
+
$status = $this->backend->doOperation(
- array( 'op' => 'create', 'content' => $content, 'dst' => $src ) );
+ array( 'op' => 'create', 'content' => $content, 'dst' => $source ) );
$this->assertEquals( true, $status->isOK(),
- "Creation of file at $src succeeded ($backendName)." );
+ "Creation of file at $source succeeded ($backendName)." );
- $newContents = $this->backend->getFileContents( array( 'src' => $src ) );
+ $newContents = $this->backend->getFileContents( array( 'src' => $source ) );
$this->assertNotEquals( false, $newContents,
- "Read of file at $src succeeded ($backendName)." );
+ "Read of file at $source succeeded ($backendName)." );
$this->assertEquals( $content, $newContents,
- "Contents read match data at $src ($backendName)." );
+ "Contents read match data at $source ($backendName)." );
}
function provider_testGetFileContents() {
$this->tearDownFiles();
}
- public function doTestGetLocalCopy( $src, $content ) {
+ public function doTestGetLocalCopy( $source, $content ) {
$backendName = $this->backendClass();
+ $this->backend->prepare( array( 'dir' => dirname( $source ) ) );
+
$status = $this->backend->doOperation(
- array( 'op' => 'create', 'content' => $content, 'dst' => $src ) );
+ array( 'op' => 'create', 'content' => $content, 'dst' => $source ) );
$this->assertEquals( true, $status->isOK(),
- "Creation of file at $src succeeded ($backendName)." );
+ "Creation of file at $source succeeded ($backendName)." );
- $tmpFile = $this->backend->getLocalCopy( array( 'src' => $src ) );
+ $tmpFile = $this->backend->getLocalCopy( array( 'src' => $source ) );
$this->assertNotNull( $tmpFile,
- "Creation of local copy of $src succeeded ($backendName)." );
+ "Creation of local copy of $source succeeded ($backendName)." );
$contents = file_get_contents( $tmpFile->getPath() );
- $this->assertNotEquals( false, $contents, "Local copy of $src exists ($backendName)." );
+ $this->assertNotEquals( false, $contents, "Local copy of $source exists ($backendName)." );
}
function provider_testGetLocalCopy() {
$this->tearDownFiles();
}
- public function doTestGetLocalReference( $src, $content ) {
+ public function doTestGetLocalReference( $source, $content ) {
$backendName = $this->backendClass();
+ $this->backend->prepare( array( 'dir' => dirname( $source ) ) );
+
$status = $this->backend->doOperation(
- array( 'op' => 'create', 'content' => $content, 'dst' => $src ) );
+ array( 'op' => 'create', 'content' => $content, 'dst' => $source ) );
$this->assertEquals( true, $status->isOK(),
- "Creation of file at $src succeeded ($backendName)." );
+ "Creation of file at $source succeeded ($backendName)." );
- $tmpFile = $this->backend->getLocalReference( array( 'src' => $src ) );
+ $tmpFile = $this->backend->getLocalReference( array( 'src' => $source ) );
$this->assertNotNull( $tmpFile,
- "Creation of local copy of $src succeeded ($backendName)." );
+ "Creation of local copy of $source succeeded ($backendName)." );
$contents = file_get_contents( $tmpFile->getPath() );
- $this->assertNotEquals( false, $contents, "Local copy of $src exists ($backendName)." );
+ $this->assertNotEquals( false, $contents, "Local copy of $source exists ($backendName)." );
}
function provider_testGetLocalReference() {
$ops = array();
foreach ( $files as $file ) {
$ops[] = array( 'op' => 'create', 'content' => 'xxy', 'dst' => $file );
+ $this->backend->prepare( array( 'dir' => dirname( $file ) ) );
}
$status = $this->backend->doOperations( $ops );
$this->assertEquals( true, $status->isOK(),