24use Wikimedia\AtEase\AtEase;
25use Wikimedia\Timestamp\ConvertibleTimestamp;
52 if ( $dst ===
null ) {
53 $status->fatal(
'backend-fail-invalidpath', $params[
'dst'] );
58 $this->files[$dst] = [
59 'data' => $params[
'content'],
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'] );
136 if ( !isset( $this->files[$src] ) ) {
137 if ( empty( $params[
'ignoreMissingSource'] ) ) {
138 $status->fatal(
'backend-fail-delete', $params[
'src'] );
144 unset( $this->files[$src] );
151 if ( $src ===
null ) {
155 if ( isset( $this->files[$src] ) ) {
157 'mtime' => $this->files[$src][
'mtime'],
158 'size' => strlen( $this->files[$src][
'data'] ),
167 foreach ( $params[
'srcs'] as $srcPath ) {
169 if ( $src ===
null ) {
171 } elseif ( !isset( $this->files[$src] ) ) {
176 $fsFile = $this->tmpFileFactory->newTempFSFile(
'localcopy_',
$ext );
178 $bytes = file_put_contents( $fsFile->getPath(), $this->files[$src][
'data'] );
179 if ( $bytes !== strlen( $this->files[$src][
'data'] ) ) {
184 $tmpFiles[$srcPath] = $fsFile;
191 $prefix = rtrim(
"$container/$dir",
'/' ) .
'/';
192 foreach ( $this->files as
$path => $data ) {
193 if ( strpos(
$path, $prefix ) === 0 ) {
203 $prefix = rtrim(
"$container/$dir",
'/' ) .
'/';
204 $prefixLen = strlen( $prefix );
205 foreach ( $this->files as
$path => $data ) {
206 if ( strpos(
$path, $prefix ) === 0 ) {
207 $relPath = substr(
$path, $prefixLen );
208 if ( $relPath ===
false ) {
210 } elseif ( strpos( $relPath,
'/' ) ===
false ) {
213 $parts = array_slice( explode(
'/', $relPath ), 0, -1 );
214 if ( !empty( $params[
'topOnly'] ) ) {
215 $dirs[$parts[0]] = 1;
218 foreach ( $parts as $part ) {
219 $dir = ( $current ===
'' ) ? $part :
"$current/$part";
227 return array_keys( $dirs );
232 $prefix = rtrim(
"$container/$dir",
'/' ) .
'/';
233 $prefixLen = strlen( $prefix );
234 foreach ( $this->files as
$path => $data ) {
235 if ( strpos(
$path, $prefix ) === 0 ) {
236 $relPath = substr(
$path, $prefixLen );
237 if ( $relPath ===
false ) {
239 } elseif ( !empty( $params[
'topOnly'] ) && strpos( $relPath,
'/' ) !==
false ) {
261 if ( $relPath ===
null ) {
265 return ( $relPath !==
'' ) ?
"$fullCont/$relPath" : $fullCont;
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 false $RES_ABSENT
Idiom for "no result due to missing file" (since 1.34)
static null $RES_ERROR
Idiom for "no result due to I/O errors" (since 1.34)
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 Stable to override.
getDirectoryListInternal( $container, $dir, array $params)
Do not call this function from places outside FileBackend.
doStoreInternal(array $params)
doDeleteInternal(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.
if(!is_readable( $file)) $ext