MediaWiki master
FileStatePredicates Class Reference

Helper class for tracking counterfactual file states when pre-checking file operation batches. More...

Public Member Functions

 __construct ()
 
 assumeFileDoesNotExist (string $path)
 Predicate that no file exists at the path.
 
 assumeFileExists (string $path, $size, $sha1Base36)
 Predicate that a file exists at the path.
 
 resolveFileExistence (string $path, $curExistenceFunc)
 Get the hypothetical existance a file given predicated and current state of files.
 
 resolveFileSha1Base36 (string $path, $curSha1Func)
 Get the hypothetical SHA-1 hash of a file given predicated and current state of files.
 
 resolveFileSize (string $path, $curSizeFunc)
 Get the hypothetical size of a file given predicated and current state of files.
 
 snapshot (array $paths)
 

Protected Attributes

const EXISTS = 'exists'
 
const SHA1 = 'sha1'
 
const SIZE = 'size'
 

Detailed Description

Helper class for tracking counterfactual file states when pre-checking file operation batches.

The file states are represented with (existence,size,sha1) triples. When combined with the current state of files in the backend, this can be used to simulate how a batch of operations would play out as a "dry run". This is used in FileBackend::doOperations() to bail out if any failure can be predicted before modifying any data. This includes file operation batches where the same file gets modified by different operations within the batch.

Access: internal
Only for use within FileBackend

Definition at line 33 of file FileStatePredicates.php.

Constructor & Destructor Documentation

◆ __construct()

FileStatePredicates::__construct ( )

Definition at line 41 of file FileStatePredicates.php.

Member Function Documentation

◆ assumeFileDoesNotExist()

FileStatePredicates::assumeFileDoesNotExist ( string $path)

Predicate that no file exists at the path.

Parameters
string$pathStorage path

Definition at line 65 of file FileStatePredicates.php.

References $path.

Referenced by CopyFileOp\doPrecheck(), DeleteFileOp\doPrecheck(), and MoveFileOp\doPrecheck().

◆ assumeFileExists()

FileStatePredicates::assumeFileExists ( string $path,
$size,
$sha1Base36 )

Predicate that a file exists at the path.

Parameters
string$pathStorage path
int | false | Closure$sizeFile size or idempotent function yielding the size
string | Closure$sha1Base36File hash, or, idempotent function yielding the hash

Definition at line 52 of file FileStatePredicates.php.

References $path.

Referenced by CopyFileOp\doPrecheck(), CreateFileOp\doPrecheck(), DescribeFileOp\doPrecheck(), MoveFileOp\doPrecheck(), and StoreFileOp\doPrecheck().

◆ resolveFileExistence()

FileStatePredicates::resolveFileExistence ( string $path,
$curExistenceFunc )

Get the hypothetical existance a file given predicated and current state of files.

Parameters
string$pathStorage path
Closure$curExistenceFuncFunction to compute the current existence for a given path
Returns
bool|null Whether the file exists; null on error

Definition at line 80 of file FileStatePredicates.php.

References $path.

Referenced by FileOp\resolveFileExistence().

◆ resolveFileSha1Base36()

FileStatePredicates::resolveFileSha1Base36 ( string $path,
$curSha1Func )

Get the hypothetical SHA-1 hash of a file given predicated and current state of files.

Parameters
string$pathStorage path
Closure$curSha1FuncFunction to compute the current SHA-1 hash for a given path
Returns
string|false Base 36 SHA-1 hash; false on error

Definition at line 102 of file FileStatePredicates.php.

References $path.

Referenced by FileOp\resolveFileSha1Base36().

◆ resolveFileSize()

FileStatePredicates::resolveFileSize ( string $path,
$curSizeFunc )

Get the hypothetical size of a file given predicated and current state of files.

Parameters
string$pathStorage path
Closure$curSizeFuncFunction to compute the current size for a given path
Returns
int|false Bytes; false on error

Definition at line 91 of file FileStatePredicates.php.

References $path.

Referenced by FileOp\resolveFileSize().

◆ snapshot()

FileStatePredicates::snapshot ( array $paths)
Parameters
string[]$pathsList of storage paths
Returns
self Clone predicates limited to the given paths

Definition at line 132 of file FileStatePredicates.php.

References $path.

Referenced by FileOp\precheck().

Member Data Documentation

◆ EXISTS

const FileStatePredicates::EXISTS = 'exists'
protected

Definition at line 34 of file FileStatePredicates.php.

◆ SHA1

const FileStatePredicates::SHA1 = 'sha1'
protected

Definition at line 36 of file FileStatePredicates.php.

◆ SIZE

const FileStatePredicates::SIZE = 'size'
protected

Definition at line 35 of file FileStatePredicates.php.


The documentation for this class was generated from the following file: