24 use Wikimedia\AtEase\AtEase;
25 use 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;