24use Wikimedia\AtEase\AtEase;
26use Wikimedia\Timestamp\ConvertibleTimestamp;
53 if ( $dst ===
null ) {
54 $status->fatal(
'backend-fail-invalidpath',
$params[
'dst'] );
59 $this->files[$dst] = [
61 'mtime' => ConvertibleTimestamp::convert( TS_MW, time() )
71 if ( $dst ===
null ) {
72 $status->fatal(
'backend-fail-invalidpath',
$params[
'dst'] );
77 AtEase::suppressWarnings();
78 $data = file_get_contents(
$params[
'src'] );
79 AtEase::restoreWarnings();
80 if ( $data ===
false ) {
81 $status->fatal(
'backend-fail-store',
$params[
'src'],
$params[
'dst'] );
86 $this->files[$dst] = [
88 'mtime' => ConvertibleTimestamp::convert( TS_MW, time() )
98 if ( $src ===
null ) {
99 $status->fatal(
'backend-fail-invalidpath',
$params[
'src'] );
105 if ( $dst ===
null ) {
106 $status->fatal(
'backend-fail-invalidpath',
$params[
'dst'] );
111 if ( !isset( $this->files[$src] ) ) {
112 if ( empty(
$params[
'ignoreMissingSource'] ) ) {
113 $status->fatal(
'backend-fail-copy',
$params[
'src'],
$params[
'dst'] );
119 $this->files[$dst] = [
120 'data' => $this->files[$src][
'data'],
121 'mtime' => ConvertibleTimestamp::convert( TS_MW, time() )
131 if ( $src ===
null ) {
132 $status->fatal(
'backend-fail-invalidpath',
$params[
'src'] );
138 if ( $dst ===
null ) {
139 $status->fatal(
'backend-fail-invalidpath',
$params[
'dst'] );
144 if ( !isset( $this->files[$src] ) ) {
145 if ( empty(
$params[
'ignoreMissingSource'] ) ) {
146 $status->fatal(
'backend-fail-move',
$params[
'src'],
$params[
'dst'] );
152 $this->files[$dst] = $this->files[$src];
153 unset( $this->files[$src] );
154 $this->files[$dst][
'mtime'] = ConvertibleTimestamp::convert( TS_MW, time() );
163 if ( $src ===
null ) {
164 $status->fatal(
'backend-fail-invalidpath',
$params[
'src'] );
169 if ( !isset( $this->files[$src] ) ) {
170 if ( empty(
$params[
'ignoreMissingSource'] ) ) {
171 $status->fatal(
'backend-fail-delete',
$params[
'src'] );
177 unset( $this->files[$src] );
184 if ( $src ===
null ) {
185 return self::RES_ERROR;
188 if ( isset( $this->files[$src] ) ) {
190 'mtime' => $this->files[$src][
'mtime'],
191 'size' => strlen( $this->files[$src][
'data'] ),
195 return self::RES_ABSENT;
200 foreach (
$params[
'srcs'] as $srcPath ) {
202 if ( $src ===
null ) {
203 $fsFile = self::RES_ERROR;
204 } elseif ( !isset( $this->files[$src] ) ) {
205 $fsFile = self::RES_ABSENT;
208 $ext = FileBackend::extensionFromPath( $src );
209 $fsFile = $this->tmpFileFactory->newTempFSFile(
'localcopy_', $ext );
211 $bytes = file_put_contents( $fsFile->getPath(), $this->files[$src][
'data'] );
212 if ( $bytes !== strlen( $this->files[$src][
'data'] ) ) {
213 $fsFile = self::RES_ERROR;
217 $tmpFiles[$srcPath] = $fsFile;
224 $prefix = rtrim(
"$container/$dir",
'/' ) .
'/';
225 foreach ( $this->files as
$path => $data ) {
226 if ( strpos(
$path, $prefix ) === 0 ) {
236 $prefix = rtrim(
"$container/$dir",
'/' ) .
'/';
237 $prefixLen = strlen( $prefix );
238 foreach ( $this->files as
$path => $data ) {
239 if ( strpos(
$path, $prefix ) === 0 ) {
240 $relPath = substr(
$path, $prefixLen );
241 if ( $relPath ===
false ) {
243 } elseif ( strpos( $relPath,
'/' ) ===
false ) {
246 $parts = array_slice( explode(
'/', $relPath ), 0, -1 );
247 if ( !empty(
$params[
'topOnly'] ) ) {
248 $dirs[$parts[0]] = 1;
251 foreach ( $parts as $part ) {
252 $dir = ( $current ===
'' ) ? $part :
"$current/$part";
260 return array_keys( $dirs );
265 $prefix = rtrim(
"$container/$dir",
'/' ) .
'/';
266 $prefixLen = strlen( $prefix );
267 foreach ( $this->files as
$path => $data ) {
268 if ( strpos(
$path, $prefix ) === 0 ) {
269 $relPath = substr(
$path, $prefixLen );
270 if ( $relPath ===
false ) {
272 } elseif ( !empty(
$params[
'topOnly'] ) && strpos( $relPath,
'/' ) !==
false ) {
294 if ( $relPath ===
null ) {
298 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...
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.