*/
class FileRepo {
const FILES_ONLY = 1;
+
const DELETE_SOURCE = 1;
const OVERWRITE = 2;
const OVERWRITE_SAME = 4;
- const SKIP_VALIDATION = 8;
+ const SKIP_LOCKING = 8;
/** @var FileBackendBase */
protected $backend;
* self::OVERWRITE Overwrite an existing destination file instead of failing
* self::OVERWRITE_SAME Overwrite the file if the destination exists and has the
* same contents as the source
+ * self::SKIP_LOCKING Skip any file locking when doing the store
* @return FileRepoStatus
*/
public function store( $srcPath, $dstZone, $dstRel, $flags = 0 ) {
* self::OVERWRITE Overwrite an existing destination file instead of failing
* self::OVERWRITE_SAME Overwrite the file if the destination exists and has the
* same contents as the source
+ * self::SKIP_LOCKING Skip any file locking when doing the store
* @return FileRepoStatus
*/
public function storeBatch( $triplets, $flags = 0 ) {
$backend = $this->backend; // convenience
- // Try creating directories
- $status = $this->initZones();
- if ( !$status->isOK() ) {
- return $status;
- }
-
$status = $this->newGood();
$operations = array();
// Execute the store operation for each triplet
$opts = array( 'ignoreErrors' => true );
+ if ( $flags & self::SKIP_LOCKING ) {
+ $opts['nonLocking'] = true;
+ }
$status->merge( $backend->doOperations( $operations, $opts ) );
// Cleanup for disk source files...
foreach ( $sourceFSFilesToDelete as $file ) {
$dstRel = "{$hashPath}{$date}!{$originalName}";
$dstUrlRel = $hashPath . $date . '!' . rawurlencode( $originalName );
- $result = $this->store( $srcPath, 'temp', $dstRel );
+ $result = $this->store( $srcPath, 'temp', $dstRel, self::SKIP_LOCKING );
$result->value = $this->getVirtualUrl( 'temp' ) . '/' . $dstUrlRel;
return $result;
}
* @return Either array of files and existence flags, or false
*/
public function fileExistsBatch( $files, $flags = 0 ) {
- if ( !$this->initZones() ) {
- return false;
- }
$result = array();
foreach ( $files as $key => $file ) {
if ( self::isVirtualUrl( $file ) ) {
$thumb = $this->handler->getTransform( $this, $tmpThumbPath, $thumbUrl, $params );
}
} elseif ( $thumb->hasFile() && !$thumb->fileIsSource() ) {
- // @TODO: use a FileRepo store function
- $op = array( 'op' => 'store',
- 'src' => $tmpThumbPath, 'dst' => $thumbPath, 'overwriteDest' => true );
// Copy any thumbnail from the FS into storage at $dstpath
- $opts = array( 'ignoreErrors' => true, 'nonLocking' => true ); // performance
- if ( !$this->getRepo()->getBackend()->doOperation( $op, $opts )->isOK() ) {
+ $status = $this->repo->store(
+ $tmpThumbPath, 'thumb', $this->getThumbRel( $thumbName ),
+ FileRepo::OVERWRITE | FileRepo::SKIP_LOCKING );
+ if ( !$status->isOK() ) {
return new MediaTransformError( 'thumbnail_error',
$params['width'], 0, wfMsg( 'thumbnail-dest-create' ) );
}
}
/**
- * Get the path of the file relative to the public zone root
+ * Get the path of the file relative to the public zone root.
+ * This function is overriden in OldLocalFile to be like getArchiveRel().
*
* @return string
*/
}
/**
- * Get urlencoded relative path of the file
- *
- * @return string
- */
- function getUrlRel() {
- return $this->getHashPath() . rawurlencode( $this->getName() );
- }
-
- /**
- * Get the relative path for an archived file
+ * Get the path of an archived file relative to the public zone root
*
* @param $suffix bool|string if not false, the name of an archived thumbnail file
*
}
/**
- * Get the relative path for an archived file's thumbs directory
+ * Get the path, relative to the thumbnail zone root, of the
+ * thumbnail directory or a particular file if $suffix is specified
+ *
+ * @param $suffix bool|string if not false, the name of a thumbnail file
+ *
+ * @return string
+ */
+ function getThumbRel( $suffix = false ) {
+ $path = $this->getRel();
+ if ( $suffix !== false ) {
+ $path .= '/' . $suffix;
+ }
+ return $path;
+ }
+
+ /**
+ * Get urlencoded path of the file relative to the public zone root.
+ * This function is overriden in OldLocalFile to be like getArchiveUrl().
+ *
+ * @return string
+ */
+ function getUrlRel() {
+ return $this->getHashPath() . rawurlencode( $this->getName() );
+ }
+
+ /**
+ * Get the path, relative to the thumbnail zone root, for an archived file's thumbs directory
* or a specific thumb if the $suffix is given.
*
* @param $archiveName string the timestamped name of an archived image
}
/**
- * Get the path of the archived file's thumbs, or a particular thumb if $suffix is specified
+ * Get the path of an archived file's thumbs, or a particular thumb if $suffix is specified
*
* @param $archiveName string the timestamped name of an archived image
* @param $suffix bool|string if not false, the name of a thumbnail file
*/
function getThumbPath( $suffix = false ) {
$this->assertRepoDefined();
- $path = $this->repo->getZonePath( 'thumb' ) . '/' . $this->getRel();
- if ( $suffix !== false ) {
- $path .= '/' . $suffix;
- }
- return $path;
+ return $this->repo->getZonePath( 'thumb' ) . '/' . $this->getThumbRel( $suffix );
}
/**