}
// Resolve source to a storage path if virtual
- $srcPath = $this->resolveToStoragePath( $srcPath );
+ $srcPath = $this->resolveToStoragePathIfVirtual( $srcPath );
- // Get the appropriate file operation
- if ( FileBackend::isStoragePath( $srcPath ) ) {
- $opName = 'copy';
- } else {
- $opName = 'store';
- }
+ // Copy the source file to the destination
$operations[] = [
- 'op' => $opName,
- 'src' => $srcPath,
+ 'op' => FileBackend::isStoragePath( $srcPath ) ? 'copy' : 'store',
+ 'src' => $srcPath, // storage path (copy) or local file path (store)
'dst' => $dstPath,
- 'overwrite' => $flags & self::OVERWRITE,
- 'overwriteSame' => $flags & self::OVERWRITE_SAME,
+ 'overwrite' => ( $flags & self::OVERWRITE ) ? true : false,
+ 'overwriteSame' => ( $flags & self::OVERWRITE_SAME ) ? true : false,
];
}
$path = $this->getZonePath( $zone ) . "/$rel";
} else {
// Resolve source to a storage path if virtual
- $path = $this->resolveToStoragePath( $path );
+ $path = $this->resolveToStoragePathIfVirtual( $path );
}
$operations[] = [ 'op' => 'delete', 'src' => $path ];
}
public function quickCleanDir( $dir ) {
$status = $this->newGood();
$status->merge( $this->backend->clean(
- [ 'dir' => $this->resolveToStoragePath( $dir ) ] ) );
+ [ 'dir' => $this->resolveToStoragePathIfVirtual( $dir ) ] ) );
return $status;
}
if ( $src instanceof FSFile ) {
$op = 'store';
} else {
- $src = $this->resolveToStoragePath( $src );
+ $src = $this->resolveToStoragePathIfVirtual( $src );
$op = FileBackend::isStoragePath( $src ) ? 'copy' : 'store';
}
- $dst = $this->resolveToStoragePath( $dst );
+ $dst = $this->resolveToStoragePathIfVirtual( $dst );
if ( !isset( $triple[2] ) ) {
$headers = [];
foreach ( $paths as $path ) {
$operations[] = [
'op' => 'delete',
- 'src' => $this->resolveToStoragePath( $path ),
+ 'src' => $this->resolveToStoragePathIfVirtual( $path ),
'ignoreMissingSource' => true
];
}
$sources = [];
foreach ( $srcPaths as $srcPath ) {
// Resolve source to a storage path if virtual
- $source = $this->resolveToStoragePath( $srcPath );
+ $source = $this->resolveToStoragePathIfVirtual( $srcPath );
$sources[] = $source; // chunk to merge
}
$options = $ntuple[3] ?? [];
// Resolve source to a storage path if virtual
- $srcPath = $this->resolveToStoragePath( $srcPath );
+ $srcPath = $this->resolveToStoragePathIfVirtual( $srcPath );
if ( !$this->validateFilename( $dstRel ) ) {
throw new MWException( 'Validation error in $dstRel' );
}
// Copy (or move) the source file to the destination
if ( FileBackend::isStoragePath( $srcPath ) ) {
- if ( $flags & self::DELETE_SOURCE ) {
- $operations[] = [
- 'op' => 'move',
- 'src' => $srcPath,
- 'dst' => $dstPath,
- 'overwrite' => true, // replace current
- 'headers' => $headers
- ];
- } else {
- $operations[] = [
- 'op' => 'copy',
- 'src' => $srcPath,
- 'dst' => $dstPath,
- 'overwrite' => true, // replace current
- 'headers' => $headers
- ];
- }
- } else { // FS source path
+ $operations[] = [
+ 'op' => ( $flags & self::DELETE_SOURCE ) ? 'move' : 'copy',
+ 'src' => $srcPath,
+ 'dst' => $dstPath,
+ 'overwrite' => true, // replace current
+ 'headers' => $headers
+ ];
+ } else {
$operations[] = [
'op' => 'store',
- 'src' => $src, // prefer FSFile objects
+ 'src' => $src, // FSFile (preferred) or local file path
'dst' => $dstPath,
'overwrite' => true, // replace current
'headers' => $headers
* @return Status
*/
protected function initDirectory( $dir ) {
- $path = $this->resolveToStoragePath( $dir );
+ $path = $this->resolveToStoragePathIfVirtual( $dir );
list( , $container, ) = FileBackend::splitStoragePath( $path );
$params = [ 'dir' => $path ];
$status = $this->newGood();
$status->merge( $this->backend->clean(
- [ 'dir' => $this->resolveToStoragePath( $dir ) ] ) );
+ [ 'dir' => $this->resolveToStoragePathIfVirtual( $dir ) ] ) );
return $status;
}
* @return array Map of files and existence flags, or false
*/
public function fileExistsBatch( array $files ) {
- $paths = array_map( [ $this, 'resolveToStoragePath' ], $files );
+ $paths = array_map( [ $this, 'resolveToStoragePathIfVirtual' ], $files );
$this->backend->preloadFileStat( [ 'srcs' => $paths ] );
$result = [];
foreach ( $files as $key => $file ) {
- $path = $this->resolveToStoragePath( $file );
+ $path = $this->resolveToStoragePathIfVirtual( $file );
$result[$key] = $this->backend->fileExists( [ 'src' => $path ] );
}
* @return string
* @throws MWException
*/
- protected function resolveToStoragePath( $path ) {
+ protected function resolveToStoragePathIfVirtual( $path ) {
if ( self::isVirtualUrl( $path ) ) {
return $this->resolveVirtualUrl( $path );
}
* @return TempFSFile|null Returns null on failure
*/
public function getLocalCopy( $virtualUrl ) {
- $path = $this->resolveToStoragePath( $virtualUrl );
+ $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
return $this->backend->getLocalCopy( [ 'src' => $path ] );
}
* @return FSFile|null Returns null on failure.
*/
public function getLocalReference( $virtualUrl ) {
- $path = $this->resolveToStoragePath( $virtualUrl );
+ $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
return $this->backend->getLocalReference( [ 'src' => $path ] );
}
* @return string|bool False on failure
*/
public function getFileTimestamp( $virtualUrl ) {
- $path = $this->resolveToStoragePath( $virtualUrl );
+ $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
return $this->backend->getFileTimestamp( [ 'src' => $path ] );
}
* @return int|bool False on failure
*/
public function getFileSize( $virtualUrl ) {
- $path = $this->resolveToStoragePath( $virtualUrl );
+ $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
return $this->backend->getFileSize( [ 'src' => $path ] );
}
* @return string|bool
*/
public function getFileSha1( $virtualUrl ) {
- $path = $this->resolveToStoragePath( $virtualUrl );
+ $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
return $this->backend->getFileSha1Base36( [ 'src' => $path ] );
}
* @since 1.27
*/
public function streamFileWithStatus( $virtualUrl, $headers = [], $optHeaders = [] ) {
- $path = $this->resolveToStoragePath( $virtualUrl );
+ $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
$params = [ 'src' => $path, 'headers' => $headers, 'options' => $optHeaders ];
// T172851: HHVM does not flush the output properly, causing OOM