24use Wikimedia\AtEase\AtEase;
25use Wikimedia\Timestamp\ConvertibleTimestamp;
52 if ( $dst ===
null ) {
53 $status->fatal(
'backend-fail-invalidpath',
$params[
'dst'] );
58 $this->files[$dst] = [
60 'mtime' => ConvertibleTimestamp::convert( TS_MW, time() )
70 if ( $dst ===
null ) {
71 $status->fatal(
'backend-fail-invalidpath',
$params[
'dst'] );
76 AtEase::suppressWarnings();
77 $data = file_get_contents(
$params[
'src'] );
78 AtEase::restoreWarnings();
79 if ( $data ===
false ) {
80 $status->fatal(
'backend-fail-store',
$params[
'src'],
$params[
'dst'] );
85 $this->files[$dst] = [
87 'mtime' => ConvertibleTimestamp::convert( TS_MW, time() )
97 if ( $src ===
null ) {
98 $status->fatal(
'backend-fail-invalidpath',
$params[
'src'] );
104 if ( $dst ===
null ) {
105 $status->fatal(
'backend-fail-invalidpath',
$params[
'dst'] );
110 if ( !isset( $this->files[$src] ) ) {
111 if ( empty(
$params[
'ignoreMissingSource'] ) ) {
112 $status->fatal(
'backend-fail-copy',
$params[
'src'],
$params[
'dst'] );
118 $this->files[$dst] = [
119 'data' => $this->files[$src][
'data'],
120 'mtime' => ConvertibleTimestamp::convert( TS_MW, time() )
130 if ( $src ===
null ) {
131 $status->fatal(
'backend-fail-invalidpath',
$params[
'src'] );
137 if ( $dst ===
null ) {
138 $status->fatal(
'backend-fail-invalidpath',
$params[
'dst'] );
143 if ( !isset( $this->files[$src] ) ) {
144 if ( empty(
$params[
'ignoreMissingSource'] ) ) {
145 $status->fatal(
'backend-fail-move',
$params[
'src'],
$params[
'dst'] );
151 $this->files[$dst] = $this->files[$src];
152 unset( $this->files[$src] );
153 $this->files[$dst][
'mtime'] = ConvertibleTimestamp::convert( TS_MW, time() );
162 if ( $src ===
null ) {
163 $status->fatal(
'backend-fail-invalidpath',
$params[
'src'] );
168 if ( !isset( $this->files[$src] ) ) {
169 if ( empty(
$params[
'ignoreMissingSource'] ) ) {
170 $status->fatal(
'backend-fail-delete',
$params[
'src'] );
176 unset( $this->files[$src] );
183 if ( $src ===
null ) {
184 return self::RES_ERROR;
187 if ( isset( $this->files[$src] ) ) {
189 'mtime' => $this->files[$src][
'mtime'],
190 'size' => strlen( $this->files[$src][
'data'] ),
194 return self::RES_ABSENT;
199 foreach (
$params[
'srcs'] as $srcPath ) {
201 if ( $src ===
null ) {
202 $fsFile = self::RES_ERROR;
203 } elseif ( !isset( $this->files[$src] ) ) {
204 $fsFile = self::RES_ABSENT;
208 $fsFile = $this->tmpFileFactory->newTempFSFile(
'localcopy_', $ext );
210 $bytes = file_put_contents( $fsFile->getPath(), $this->files[$src][
'data'] );
211 if ( $bytes !== strlen( $this->files[$src][
'data'] ) ) {
212 $fsFile = self::RES_ERROR;
216 $tmpFiles[$srcPath] = $fsFile;
223 $prefix = rtrim(
"$container/$dir",
'/' ) .
'/';
224 foreach ( $this->files as
$path => $data ) {
225 if ( strpos(
$path, $prefix ) === 0 ) {
235 $prefix = rtrim(
"$container/$dir",
'/' ) .
'/';
236 $prefixLen = strlen( $prefix );
237 foreach ( $this->files as
$path => $data ) {
238 if ( strpos(
$path, $prefix ) === 0 ) {
239 $relPath = substr(
$path, $prefixLen );
240 if ( $relPath ===
false ) {
242 } elseif ( strpos( $relPath,
'/' ) ===
false ) {
245 $parts = array_slice( explode(
'/', $relPath ), 0, -1 );
246 if ( !empty(
$params[
'topOnly'] ) ) {
247 $dirs[$parts[0]] = 1;
250 foreach ( $parts as $part ) {
251 $dir = ( $current ===
'' ) ? $part :
"$current/$part";
259 return array_keys( $dirs );
264 $prefix = rtrim(
"$container/$dir",
'/' ) .
'/';
265 $prefixLen = strlen( $prefix );
266 foreach ( $this->files as
$path => $data ) {
267 if ( strpos(
$path, $prefix ) === 0 ) {
268 $relPath = substr(
$path, $prefixLen );
269 if ( $relPath ===
false ) {
271 } elseif ( !empty(
$params[
'topOnly'] ) && strpos( $relPath,
'/' ) !==
false ) {
293 if ( $relPath ===
null ) {
297 return ( $relPath !==
'' ) ?
"$fullCont/$relPath" : $fullCont;
array $params
The job parameters.
Base class for all backends using particular storage medium.
resolveStoragePathReal( $storagePath)
Like resolveStoragePath() except null values are returned if the container is sharded and the shard c...
static extensionFromPath( $path, $case='lowercase')
Get the final extension from a storage or FS path.
newStatus(... $args)
Yields the result of the status wrapper callback on either:
Simulation of a backend storage in memory.
doGetLocalCopyMulti(array $params)
doDirectoryExists( $container, $dir, array $params)
doCreateInternal(array $params)
getFileListInternal( $container, $dir, array $params)
Do not call this function from places outside FileBackend.
directoriesAreVirtual()
Is this a key/value store where directories are just virtual? Virtual directories exists in so much a...
getFeatures()
Get the a bitfield of extra features supported by the backend medium.
getDirectoryListInternal( $container, $dir, array $params)
Do not call this function from places outside FileBackend.
doStoreInternal(array $params)
doDeleteInternal(array $params)
doMoveInternal(array $params)
array $files
Map of (file path => (data,mtime)
doCopyInternal(array $params)
doGetFileStat(array $params)
isPathUsableInternal( $storagePath)
Check if a file can be created or changed at a given storage path in the backend.
resolveHashKey( $storagePath)
Get the absolute file system path for a storage path.