/**
* Get the local directory corresponding to one of the three basic zones
+ *
+ * @param $zone string
+ *
+ * @return string
*/
function getZonePath( $zone ) {
switch ( $zone ) {
/**
* @see FileRepo::getZoneUrl()
+ *
+ * @param $zone string
+ *
+ * @return url
*/
function getZoneUrl( $zone ) {
switch ( $zone ) {
* Get a URL referring to this repository, with the private mwrepo protocol.
* The suffix, if supplied, is considered to be unencoded, and will be
* URL-encoded before being returned.
+ *
+ * @param $suffix string
+ *
+ * @return string
*/
function getVirtualUrl( $suffix = false ) {
$path = 'mwrepo://' . $this->name;
/**
* Get the local path corresponding to a virtual URL
+ *
+ * @param $url string
+ *
+ * @return string
*/
function resolveVirtualUrl( $url ) {
if ( substr( $url, 0, 9 ) != 'mwrepo://' ) {
- throw new MWException( __METHOD__.': unknown protoocl' );
+ throw new MWException( __METHOD__.': unknown protocol' );
}
$bits = explode( '/', substr( $url, 9 ), 3 );
}
/**
- * Deletes a batch of (zone, rel) pairs. It will try to delete each pair,
- * but ignores any errors doing so.
+ * Deletes a batch of files. Each file can be a (zone, rel) pairs, a
+ * virtual url or a real path. It will try to delete each file, but
+ * ignores any errors that may occur
*
- * @param $pairs array Pair of (zone, rel) pairs to delete
+ * @param $pairs array List of files to delete
*/
- function cleanupBatch( $pairs ) {
- foreach ( $pairs as $pair ) {
- list( $zone, $rel ) = $pair;
- $root = $this->getZonePath( $zone );
- $path = "$root/$rel";
+ function cleanupBatch( $files ) {
+ foreach ( $files as $file ) {
+ if ( is_array( $file ) ) {
+ // This is a pair, extract it
+ list( $zone, $rel ) = $file;
+ $root = $this->getZonePath( $zone );
+ $path = "$root/$rel";
+ } else {
+ if ( self::isVirtualUrl( $file ) ) {
+ // This is a virtual url, resolve it
+ $path = $this->resolveVirtualUrl( $file );
+ } else {
+ // This is a full file name
+ $path = $file;
+ }
+ }
wfSuppressWarnings();
unlink( $path );
$status = $this->newGood();
// Resolve the virtual URL
- if ( self::isVirtualUrl( $srcPath ) ) {
- $srcPath = $this->resolveVirtualUrl( $srcPath );
+ if ( self::isVirtualUrl( $toAppendPath ) ) {
+ $toAppendPath = $this->resolveVirtualUrl( $toAppendPath );
}
// Make sure the files are there
- if ( !is_file( $srcPath ) )
- $status->fatal( 'filenotfound', $srcPath );
-
if ( !is_file( $toAppendPath ) )
$status->fatal( 'filenotfound', $toAppendPath );
+ if ( !is_file( $srcPath ) )
+ $status->fatal( 'filenotfound', $srcPath );
+
if ( !$status->isOk() ) return $status;
// Do the append
- $chunk = file_get_contents( $toAppendPath );
+ $chunk = file_get_contents( $srcPath );
if( $chunk === false ) {
- $status->fatal( 'fileappenderrorread', $toAppendPath );
+ $status->fatal( 'fileappenderrorread', $srcPath );
}
if( $status->isOk() ) {
- if ( file_put_contents( $srcPath, $chunk, FILE_APPEND ) ) {
- $status->value = $srcPath;
+ if ( file_put_contents( $toAppendPath, $chunk, FILE_APPEND ) ) {
+ $status->value = $toAppendPath;
} else {
- $status->fatal( 'fileappenderror', $toAppendPath, $srcPath);
+ $status->fatal( 'fileappenderror', $srcPath, $toAppendPath);
}
}
if ( $flags & self::DELETE_SOURCE ) {
- unlink( $toAppendPath );
+ unlink( $srcPath );
}
return $status;
}
+ /* We can actually append to the files, so no-op needed here. */
+ function appendFinish( $toAppendPath ) {}
+
/**
* Checks existence of specified array of files.
*
continue;
}
$dir = opendir( $path );
- while ( false !== ( $name = readdir( $dir ) ) ) {
- call_user_func( $callback, $path . '/' . $name );
+ if ($dir) {
+ while ( false !== ( $name = readdir( $dir ) ) ) {
+ call_user_func( $callback, $path . '/' . $name );
+ }
+ closedir( $dir );
}
}
}