22use Shellbox\Command\BoxedCommand;
57 parent::__construct( $config );
58 $this->backend = $config[
'backend'];
59 $this->repoName = $config[
'repoName'];
60 $this->dbHandleFunc = $config[
'dbHandleFactory'];
85 return current( $paths );
103 foreach ( $paths as $i =>
$path ) {
104 if ( !$latest && $this->resolvedPathCache->hasField(
$path,
'target', 10 ) ) {
105 $resolved[$i] = $this->resolvedPathCache->getField(
$path,
'target' );
109 [ , $container ] = FileBackend::splitStoragePath(
$path );
111 if ( $container ===
"{$this->repoName}-public" ) {
113 if ( str_contains(
$path,
'!' ) ) {
114 $sha1 = $db->newSelectQueryBuilder()
115 ->select(
'oi_sha1' )
117 ->where( [
'oi_archive_name' =>
$name ] )
118 ->caller( __METHOD__ )->fetchField();
120 $sha1 = $db->newSelectQueryBuilder()
121 ->select(
'img_sha1' )
123 ->where( [
'img_name' =>
$name ] )
124 ->caller( __METHOD__ )->fetchField();
126 if ( $sha1 ===
null || !strlen( $sha1 ) ) {
127 $resolved[$i] =
$path;
131 $this->resolvedPathCache->setField(
$path,
'target', $resolved[$i] );
132 } elseif ( $container ===
"{$this->repoName}-deleted" ) {
134 $sha1 = substr(
$name, 0, strpos(
$name,
'.' ) );
136 $this->resolvedPathCache->setField(
$path,
'target', $resolved[$i] );
138 $resolved[$i] =
$path;
143 foreach ( $paths as $i =>
$path ) {
144 $res[$i] = $resolved[$i];
151 return $this->backend->doOperationsInternal( $this->
mungeOpPaths( $ops ), $opts );
155 return $this->backend->doQuickOperationsInternal( $this->
mungeOpPaths( $ops ), $opts );
159 return $this->backend->doPrepare(
$params );
163 return $this->backend->doSecure(
$params );
167 return $this->backend->doPublish(
$params );
171 return $this->backend->doClean(
$params );
211 $type = StreamFile::contentTypeFromPath(
$params[
'src'] );
212 if ( $type && $type !=
'unknown/unknown' ) {
213 $params[
'headers'][] =
"Content-type: $type";
238 return $this->backend->addShellboxInputFile( $command, $boxedName,
$params );
242 return $this->backend->directoryExists(
$params );
246 return $this->backend->getDirectoryList(
$params );
250 return $this->backend->getFileList(
$params );
254 return $this->backend->getFeatures();
258 $this->backend->clearCache(
null );
263 $this->backend->preloadCache( $paths );
271 return $this->backend->getScopedLocksForOps( $ops, $status );
283 if ( strlen( $sha1 ) < 3 ) {
284 throw new InvalidArgumentException(
"Invalid file SHA-1." );
286 return $this->backend->getContainerStoragePath(
"{$this->repoName}-original" ) .
287 "/{$sha1[0]}/{$sha1[1]}/{$sha1[2]}/{$sha1}";
296 protected function getDB( $index ) {
297 if ( !isset( $this->dbs[$index] ) ) {
299 $this->dbs[$index] = $func( $index );
301 return $this->dbs[$index];
312 $latest = !empty(
$params[
'latest'] );
314 if ( isset(
$params[
'src'] ) ) {
318 if ( isset(
$params[
'srcs'] ) ) {
322 return $this->backend->$function(
$params );
335 $pathMap = array_combine(
$params[
'srcs'], $origPaths );
337 $results = $this->backend->$function(
$params );
340 foreach ( $results as
$path => $result ) {
341 $contents[$pathMap[
$path]] = $result;
357 static $srcRefOps = [
'store',
'copy',
'describe' ];
358 foreach ( $ops as &$op ) {
359 if ( isset( $op[
'src'] ) && in_array( $op[
'op'], $srcRefOps ) ) {
362 if ( isset( $op[
'srcs'] ) ) {
array $params
The job parameters.
Proxy backend that manages file layout rewriting for FileRepo.
getFileSha1Base36(array $params)
Get a SHA-1 hash of the content of the file at a storage path in the backend.
__construct(array $config)
Create a new backend instance from configuration.
concatenate(array $params)
Concatenate a list of storage files into a single file system file.
streamFile(array $params)
Stream the content of the file at a storage path in the backend.
getScopedLocksForOps(array $ops, StatusValue $status)
Get an array of scoped locks needed for a batch of file operations.
getInternalBackend()
Get the underlying FileBackend that is being wrapped.
clearCache(?array $paths=null)
Invalidate any in-process file stat and property cache.
getLocalCopyMulti(array $params)
Like getLocalCopy() except it takes an array of storage paths and yields an order preserved-map of st...
doOperationsInternal(array $ops, array $opts)
fileExists(array $params)
Check if a file exists at a storage path in the backend.
getPathForSHA1( $sha1)
Get the ultimate original storage path for a file.
getDB( $index)
Get a connection to the repo file registry DB.
translateSrcParams( $function, array $params)
Translates paths found in the "src" or "srcs" keys of a params array.
mungeOpPaths(array $ops)
Translate legacy "title" source paths to their "sha1" counterparts.
getFileHttpUrl(array $params)
Return an HTTP URL to a given file that requires no authentication to use.
getLocalReferenceMulti(array $params)
Like getLocalReference() except it takes an array of storage paths and yields an order-preserved map ...
preloadCache(array $paths)
Preload persistent file stat cache and property cache into in-process cache.
getFileSize(array $params)
Get the size (bytes) of a file at a storage path in the backend.
getFileProps(array $params)
Get the properties of the content of the file at a storage path in the backend.
addShellboxInputFile(BoxedCommand $command, string $boxedName, array $params)
Add a file to a Shellbox command as an input file.
getFeatures()
Get the a bitfield of extra features supported by the backend medium.
MapCacheLRU $resolvedPathCache
translateArrayResults( $function, array $params)
Translates paths when the backend function returns results keyed by paths.
preloadFileStat(array $params)
Preload file stat information (concurrently if possible) into in-process cache.
directoryExists(array $params)
Check if a directory exists at a given storage path.
getBackendPaths(array $paths, $latest=true)
Translate legacy "title" paths to their "sha1" counterparts.
getFileList(array $params)
Get an iterator to list all stored files under a storage directory.
getFileStat(array $params)
Get quick information about a file at a storage path in the backend.
getFileTimestamp(array $params)
Get the last-modified timestamp of the file at a storage path.
getFileXAttributes(array $params)
Get metadata about a file at a storage path in the backend.
getFileContentsMulti(array $params)
Like getFileContents() except it takes an array of storage paths and returns an order preserved map o...
doQuickOperationsInternal(array $ops, array $opts)
getDirectoryList(array $params)
Get an iterator to list all directories under a storage directory.
getBackendPath( $path, $latest=true)
Translate a legacy "title" path to its "sha1" counterpart.
Store key-value entries in a size-limited in-memory LRU cache.
Generic operation result class Has warning/error list, boolean status and arbitrary value.