MediaWiki master
Wikimedia\FileBackend\FileOps\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 37 of file FileStatePredicates.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\FileBackend\FileOps\FileStatePredicates::__construct ( )

Definition at line 45 of file FileStatePredicates.php.

Member Function Documentation

◆ assumeFileDoesNotExist()

Wikimedia\FileBackend\FileOps\FileStatePredicates::assumeFileDoesNotExist ( string $path)

Predicate that no file exists at the path.

Parameters
string$pathStorage path

Definition at line 69 of file FileStatePredicates.php.

References $path.

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

◆ assumeFileExists()

Wikimedia\FileBackend\FileOps\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 56 of file FileStatePredicates.php.

References $path.

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

◆ resolveFileExistence()

Wikimedia\FileBackend\FileOps\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 84 of file FileStatePredicates.php.

References $path.

Referenced by Wikimedia\FileBackend\FileOps\FileOp\resolveFileExistence().

◆ resolveFileSha1Base36()

Wikimedia\FileBackend\FileOps\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 106 of file FileStatePredicates.php.

References $path.

Referenced by Wikimedia\FileBackend\FileOps\FileOp\resolveFileSha1Base36().

◆ resolveFileSize()

Wikimedia\FileBackend\FileOps\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 95 of file FileStatePredicates.php.

References $path.

Referenced by Wikimedia\FileBackend\FileOps\FileOp\resolveFileSize().

◆ snapshot()

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

Definition at line 136 of file FileStatePredicates.php.

References $path.

Referenced by Wikimedia\FileBackend\FileOps\FileOp\precheck().

Member Data Documentation

◆ EXISTS

const Wikimedia\FileBackend\FileOps\FileStatePredicates::EXISTS = 'exists'
protected

Definition at line 38 of file FileStatePredicates.php.

◆ SHA1

const Wikimedia\FileBackend\FileOps\FileStatePredicates::SHA1 = 'sha1'
protected

Definition at line 40 of file FileStatePredicates.php.

◆ SIZE

const Wikimedia\FileBackend\FileOps\FileStatePredicates::SIZE = 'size'
protected

Definition at line 39 of file FileStatePredicates.php.


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