MediaWiki  1.27.2
FSFileBackend Class Reference

Class for a file system (FS) based file backend. More...

Inheritance diagram for FSFileBackend:
Collaboration diagram for FSFileBackend:

Public Member Functions

 __construct (array $config)
 
 getDirectoryListInternal ($fullCont, $dirRel, array $params)
 
 getFeatures ()
 
 getFileListInternal ($fullCont, $dirRel, array $params)
 
 handleWarning ($errno, $errstr)
 
 isPathUsableInternal ($storagePath)
 
- Public Member Functions inherited from FileBackendStore
 __construct (array $config)
 
 clearCache (array $paths=null)
 
 concatenate (array $params)
 
 copyInternal (array $params)
 Copy a file from one storage path to another in the backend. More...
 
 createInternal (array $params)
 Create a file in the backend with the given contents. More...
 
 deleteInternal (array $params)
 Delete a file at the storage path. More...
 
 describeInternal (array $params)
 Alter metadata for a file at the storage path. More...
 
 directoryExists (array $params)
 
 executeOpHandlesInternal (array $fileOpHandles)
 Execute a list of FileBackendStoreOpHandle handles in parallel. More...
 
 fileExists (array $params)
 
 getDirectoryList (array $params)
 
 getDirectoryListInternal ($container, $dir, array $params)
 Do not call this function from places outside FileBackend. More...
 
 getFileContentsMulti (array $params)
 
 getFileHttpUrl (array $params)
 
 getFileList (array $params)
 
 getFileListInternal ($container, $dir, array $params)
 Do not call this function from places outside FileBackend. More...
 
 getFileProps (array $params)
 
 getFileSha1Base36 (array $params)
 
 getFileSize (array $params)
 
 getFileStat (array $params)
 
 getFileTimestamp (array $params)
 
 getFileXAttributes (array $params)
 
 getLocalCopyMulti (array $params)
 
 getLocalReferenceMulti (array $params)
 
 getOperationsInternal (array $ops)
 Return a list of FileOp objects from a list of operations. More...
 
 getPathsToLockForOpsInternal (array $performOps)
 Get a list of storage paths to lock for a list of operations Returns an array with LockManager::LOCK_UW (shared locks) and LockManager::LOCK_EX (exclusive locks) keys, each corresponding to a list of storage paths to be locked. More...
 
 getScopedLocksForOps (array $ops, Status $status)
 
 isPathUsableInternal ($storagePath)
 Check if a file can be created or changed at a given storage path. More...
 
 isSingleShardPathInternal ($storagePath)
 Check if a storage path maps to a single shard. More...
 
 maxFileSizeInternal ()
 Get the maximum allowable file size given backend medium restrictions and basic performance constraints. More...
 
 moveInternal (array $params)
 Move a file from one storage path to another in the backend. More...
 
 nullInternal (array $params)
 No-op file operation that does nothing. More...
 
 preloadCache (array $paths)
 
 preloadFileStat (array $params)
 
 storeInternal (array $params)
 Store a file into the backend from a file on disk. More...
 
 streamFile (array $params)
 
- Public Member Functions inherited from FileBackend
 __construct (array $config)
 Create a new backend instance from configuration. More...
 
 clean (array $params)
 Delete a storage directory if it is empty. More...
 
 clearCache (array $paths=null)
 Invalidate any in-process file stat and property cache. More...
 
 concatenate (array $params)
 Concatenate a list of storage files into a single file system file. More...
 
 copy (array $params, array $opts=[])
 Performs a single copy operation. More...
 
 create (array $params, array $opts=[])
 Performs a single create operation. More...
 
 delete (array $params, array $opts=[])
 Performs a single delete operation. More...
 
 describe (array $params, array $opts=[])
 Performs a single describe operation. More...
 
 directoryExists (array $params)
 Check if a directory exists at a given storage path. More...
 
 doOperation (array $op, array $opts=[])
 Same as doOperations() except it takes a single operation. More...
 
 doOperations (array $ops, array $opts=[])
 This is the main entry point into the backend for write operations. More...
 
 doQuickOperation (array $op)
 Same as doQuickOperations() except it takes a single operation. More...
 
 doQuickOperations (array $ops, array $opts=[])
 Perform a set of independent file operations on some files. More...
 
 fileExists (array $params)
 Check if a file exists at a storage path in the backend. More...
 
 getContainerStoragePath ($container)
 Get the storage path for the given container for this backend. More...
 
 getDirectoryList (array $params)
 Get an iterator to list all directories under a storage directory. More...
 
 getFeatures ()
 Get the a bitfield of extra features supported by the backend medium. More...
 
 getFileContents (array $params)
 Get the contents of a file at a storage path in the backend. More...
 
 getFileContentsMulti (array $params)
 Like getFileContents() except it takes an array of storage paths and returns a map of storage paths to strings (or null on failure). More...
 
 getFileHttpUrl (array $params)
 Return an HTTP URL to a given file that requires no authentication to use. More...
 
 getFileList (array $params)
 Get an iterator to list all stored files under a storage directory. More...
 
 getFileProps (array $params)
 Get the properties of the file at a storage path in the backend. More...
 
 getFileSha1Base36 (array $params)
 Get a SHA-1 hash of the file at a storage path in the backend. More...
 
 getFileSize (array $params)
 Get the size (bytes) of a file at a storage path in the backend. More...
 
 getFileStat (array $params)
 Get quick information about a file at a storage path in the backend. More...
 
 getFileTimestamp (array $params)
 Get the last-modified timestamp of the file at a storage path. More...
 
 getFileXAttributes (array $params)
 Get metadata about a file at a storage path in the backend. More...
 
 getJournal ()
 Get the file journal object for this backend. More...
 
 getLocalCopy (array $params)
 Get a local copy on disk of the file at a storage path in the backend. More...
 
 getLocalCopyMulti (array $params)
 Like getLocalCopy() except it takes an array of storage paths and returns a map of storage paths to TempFSFile objects (or null on failure). More...
 
 getLocalReference (array $params)
 Returns a file system file, identical to the file at a storage path. More...
 
 getLocalReferenceMulti (array $params)
 Like getLocalReference() except it takes an array of storage paths and returns a map of storage paths to FSFile objects (or null on failure). More...
 
 getName ()
 Get the unique backend name. More...
 
 getReadOnlyReason ()
 Get an explanatory message if this backend is read-only. More...
 
 getRootStoragePath ()
 Get the root storage path of this backend. More...
 
 getScopedFileLocks (array $paths, $type, Status $status, $timeout=0)
 Lock the files at the given storage paths in the backend. More...
 
 getScopedLocksForOps (array $ops, Status $status)
 Get an array of scoped locks needed for a batch of file operations. More...
 
 getTopDirectoryList (array $params)
 Same as FileBackend::getDirectoryList() except only lists directories that are immediately under the given directory. More...
 
 getTopFileList (array $params)
 Same as FileBackend::getFileList() except only lists files that are immediately under the given directory. More...
 
 getWikiId ()
 Get the wiki identifier used for this backend (possibly empty). More...
 
 hasFeatures ($bitfield)
 Check if the backend medium supports a field of extra features. More...
 
 isReadOnly ()
 Check if this backend is read-only. More...
 
 lockFiles (array $paths, $type, $timeout=0)
 Lock the files at the given storage paths in the backend. More...
 
 move (array $params, array $opts=[])
 Performs a single move operation. More...
 
 preloadCache (array $paths)
 Preload persistent file stat cache and property cache into in-process cache. More...
 
 preloadFileStat (array $params)
 Preload file stat information (concurrently if possible) into in-process cache. More...
 
 prepare (array $params)
 Prepare a storage directory for usage. More...
 
 publish (array $params)
 Remove measures to block web access to a storage directory and the container it belongs to. More...
 
 quickCopy (array $params)
 Performs a single quick copy operation. More...
 
 quickCreate (array $params)
 Performs a single quick create operation. More...
 
 quickDelete (array $params)
 Performs a single quick delete operation. More...
 
 quickDescribe (array $params)
 Performs a single quick describe operation. More...
 
 quickMove (array $params)
 Performs a single quick move operation. More...
 
 quickStore (array $params)
 Performs a single quick store operation. More...
 
 secure (array $params)
 Take measures to block web access to a storage directory and the container it belongs to. More...
 
 store (array $params, array $opts=[])
 Performs a single store operation. More...
 
 streamFile (array $params)
 Stream the file at a storage path in the backend. More...
 
 unlockFiles (array $paths, $type)
 Unlock the files at the given storage paths in the backend. More...
 

Protected Member Functions

 chmod ($path)
 Chmod a file, suppressing the warnings. More...
 
 cleanPathSlashes ($path)
 Clean up directory separators for the given OS. More...
 
 containerFSRoot ($shortCont, $fullCont)
 Given the short (unresolved) and full (resolved) name of a container, return the file system path of the container. More...
 
 directoriesAreVirtual ()
 
 doCleanInternal ($fullCont, $dirRel, array $params)
 
 doClearCache (array $paths=null)
 
 doCopyInternal (array $params)
 
 doCreateInternal (array $params)
 
 doDeleteInternal (array $params)
 
 doDirectoryExists ($fullCont, $dirRel, array $params)
 
 doExecuteOpHandlesInternal (array $fileOpHandles)
 
 doGetFileStat (array $params)
 
 doGetLocalCopyMulti (array $params)
 
 doGetLocalReferenceMulti (array $params)
 
 doMoveInternal (array $params)
 
 doPrepareInternal ($fullCont, $dirRel, array $params)
 
 doPublishInternal ($fullCont, $dirRel, array $params)
 
 doSecureInternal ($fullCont, $dirRel, array $params)
 
 doStoreInternal (array $params)
 
 htaccessPrivate ()
 Return the text of a .htaccess file to make a directory private. More...
 
 indexHtmlPrivate ()
 Return the text of an index.html file to hide directory listings. More...
 
 isLegalRelPath ($path)
 Sanity check a relative file system path for validity. More...
 
 resolveContainerPath ($container, $relStoragePath)
 
 resolveToFSPath ($storagePath)
 Get the absolute file system path for a storage path. More...
 
 trapWarnings ()
 Listen for E_WARNING errors and track whether any happen. More...
 
 untrapWarnings ()
 Stop listening for E_WARNING errors and return true if any happened. More...
 
- Protected Member Functions inherited from FileBackendStore
 deleteContainerCache ($container)
 Delete the cached info for a container. More...
 
 deleteFileCache ($path)
 Delete the cached stat info for a file path. More...
 
 directoriesAreVirtual ()
 Is this a key/value store where directories are just virtual? Virtual directories exists in so much as files exists that are prefixed with the directory path followed by a forward slash. More...
 
 doClean (array $params)
 
 doCleanInternal ($container, $dir, array $params)
 
 doClearCache (array $paths=null)
 Clears any additional stat caches for storage paths. More...
 
 doConcatenate (array $params)
 
 doCopyInternal (array $params)
 
 doCreateInternal (array $params)
 
 doDeleteInternal (array $params)
 
 doDescribeInternal (array $params)
 
 doDirectoryExists ($container, $dir, array $params)
 
 doExecuteOpHandlesInternal (array $fileOpHandles)
 
 doGetFileContentsMulti (array $params)
 
 doGetFileSha1Base36 (array $params)
 
 doGetFileStat (array $params)
 
 doGetFileStatMulti (array $params)
 Get file stat information (concurrently if possible) for several files. More...
 
 doGetFileXAttributes (array $params)
 
 doGetLocalCopyMulti (array $params)
 
 doGetLocalReferenceMulti (array $params)
 
 doMoveInternal (array $params)
 
 doOperationsInternal (array $ops, array $opts)
 
 doPrepare (array $params)
 
 doPrepareInternal ($container, $dir, array $params)
 
 doPrimeContainerCache (array $containerInfo)
 Fill the backend-specific process cache given an array of resolved container names and their corresponding cached info. More...
 
 doPublish (array $params)
 
 doPublishInternal ($container, $dir, array $params)
 
 doQuickOperationsInternal (array $ops)
 
 doSecure (array $params)
 
 doSecureInternal ($container, $dir, array $params)
 
 doStoreInternal (array $params)
 
 doStreamFile (array $params)
 
 fullContainerName ($container)
 Get the full container name, including the wiki ID prefix. More...
 
 getContainerHashLevels ($container)
 Get the sharding config for a container. More...
 
 getContainerShard ($container, $relPath)
 Get the container name shard suffix for a given path. More...
 
 getContainerSuffixes ($container)
 Get a list of full container shard suffixes for a container. More...
 
 getContentType ($storagePath, $content, $fsPath)
 Get the content type to use in HEAD/GET requests for a file. More...
 
 primeContainerCache (array $items)
 Do a batch lookup from cache for container stats for all containers used in a list of container names or storage paths objects. More...
 
 primeFileCache (array $items)
 Do a batch lookup from cache for file stats for all paths used in a list of storage paths or FileOp objects. More...
 
 resolveContainerName ($container)
 Resolve a container name, checking if it's allowed by the backend. More...
 
 resolveContainerPath ($container, $relStoragePath)
 Resolve a relative storage path, checking if it's allowed by the backend. More...
 
 resolveStoragePath ($storagePath)
 Splits a storage path into an internal container name, an internal relative file name, and a container shard suffix. More...
 
 resolveStoragePathReal ($storagePath)
 Like resolveStoragePath() except null values are returned if the container is sharded and the shard could not be determined or if the path ends with '/'. More...
 
 sanitizeOpHeaders (array $op)
 Normalize and filter HTTP headers from a file operation. More...
 
 setConcurrencyFlags (array $opts)
 Set the 'concurrency' option from a list of operation options. More...
 
 setContainerCache ($container, array $val)
 Set the cached info for a container. More...
 
 setFileCache ($path, array $val)
 Set the cached stat info for a file path. More...
 
- Protected Member Functions inherited from FileBackend
 doClean (array $params)
 
 doOperationsInternal (array $ops, array $opts)
 
 doPrepare (array $params)
 
 doPublish (array $params)
 
 doQuickOperationsInternal (array $ops)
 
 doSecure (array $params)
 
 getScopedPHPBehaviorForOps ()
 Enter file operation scope. More...
 
 resolveFSFileObjects (array $ops)
 Convert FSFile 'src' paths to string paths (with an 'srcRef' field set to the FSFile) More...
 

Protected Attributes

string $basePath
 Directory holding the container directories. More...
 
array $containerPaths = []
 Map of container names to root paths for custom container paths. More...
 
string $currentUser
 OS username running this script. More...
 
int $fileMode
 File permission mode. More...
 
string $fileOwner
 Required OS username to own files. More...
 
array $hadWarningErrors = []
 
- Protected Attributes inherited from FileBackendStore
ProcessCacheLRU $cheapCache
 Map of paths to small (RAM/disk) cache items. More...
 
ProcessCacheLRU $expensiveCache
 Map of paths to large (RAM/disk) cache items. More...
 
 $maxFileSize = 4294967296
 
WANObjectCache $memCache
 
callable $mimeCallback
 Method to get the MIME type of files. More...
 
array $shardViaHashLevels = []
 Map of container names to sharding config. More...
 
- Protected Attributes inherited from FileBackend
int $concurrency
 How many operations can be done in parallel. More...
 
FileJournal $fileJournal
 
LockManager $lockManager
 
string $name
 Unique backend name. More...
 
string $parallelize
 When to do operations in parallel. More...
 
string $readOnly
 Read-only explanation message. More...
 
string $wikiId
 Unique wiki name. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from FileBackend
static extensionFromPath ($path, $case= 'lowercase')
 Get the final extension from a storage or FS path. More...
 
static isPathTraversalFree ($path)
 Check if a relative path has no directory traversals. More...
 
static isStoragePath ($path)
 Check if a given path is a "mwstore://" path. More...
 
static makeContentDisposition ($type, $filename= '')
 Build a Content-Disposition header value per RFC 6266. More...
 
static normalizeStoragePath ($storagePath)
 Normalize a storage path by cleaning up directory separators. More...
 
static parentStoragePath ($storagePath)
 Get the parent storage directory of a storage path. More...
 
static splitStoragePath ($storagePath)
 Split a storage path into a backend name, a container name, and a relative file path. More...
 
- Public Attributes inherited from FileBackendStore
const CACHE_CHEAP_SIZE = 500
 
const CACHE_EXPENSIVE_SIZE = 5
 
const CACHE_TTL = 10
 
- Public Attributes inherited from FileBackend
const ATTR_HEADERS = 1
 Bitfield flags for supported features. More...
 
const ATTR_METADATA = 2
 
const ATTR_UNICODE_PATHS = 4
 
- Static Protected Member Functions inherited from FileBackendStore
static isValidContainerName ($container)
 Check if a full container name is valid. More...
 
static isValidShortContainerName ($container)
 Check if a short container name is valid. More...
 
static normalizeXAttributes (array $xattr)
 Normalize file headers/metadata to the FileBackend::getFileXAttributes() format. More...
 
- Static Protected Member Functions inherited from FileBackend
static normalizeContainerPath ($path)
 Validate and normalize a relative storage path. More...
 

Detailed Description

Class for a file system (FS) based file backend.

All "containers" each map to a directory under the backend's base directory. For backwards-compatibility, some container paths can be set to custom paths. The wiki ID will not be used in any custom paths, so this should be avoided.

Having directories with thousands of files will diminish performance. Sharding can be accomplished by using FileRepo-style hash paths.

Status messages should avoid mentioning the internal FS paths. PHP warnings are assumed to be logged rather than output.

Since
1.19

Definition at line 41 of file FSFileBackend.php.

Constructor & Destructor Documentation

FSFileBackend::__construct ( array  $config)
See also
FileBackendStore::__construct() Additional $config params include:
Parameters
array$config

Definition at line 69 of file FSFileBackend.php.

References $path, array(), and as.

Member Function Documentation

FSFileBackend::chmod (   $path)
protected

Chmod a file, suppressing the warnings.

Parameters
string$pathAbsolute file system path
Returns
bool Success

Definition at line 723 of file FSFileBackend.php.

References $path, trapWarnings(), and untrapWarnings().

Referenced by doCopyInternal(), doCreateInternal(), doExecuteOpHandlesInternal(), doGetLocalCopyMulti(), and doStoreInternal().

FSFileBackend::cleanPathSlashes (   $path)
protected

Clean up directory separators for the given OS.

Parameters
string$pathFS path
Returns
string

Definition at line 755 of file FSFileBackend.php.

References $path, and wfIsWindows().

Referenced by doCopyInternal(), doCreateInternal(), doDeleteInternal(), doMoveInternal(), and doStoreInternal().

FSFileBackend::containerFSRoot (   $shortCont,
  $fullCont 
)
protected

Given the short (unresolved) and full (resolved) name of a container, return the file system path of the container.

Parameters
string$shortCont
string$fullCont
Returns
string|null

Definition at line 136 of file FSFileBackend.php.

Referenced by doCleanInternal(), doDirectoryExists(), doPrepareInternal(), doPublishInternal(), doSecureInternal(), getDirectoryListInternal(), getFileListInternal(), and resolveToFSPath().

FSFileBackend::directoriesAreVirtual ( )
protected

Definition at line 678 of file FSFileBackend.php.

FSFileBackend::doCleanInternal (   $fullCont,
  $dirRel,
array  $params 
)
protected
FSFileBackend::doClearCache ( array  $paths = null)
protected

Definition at line 565 of file FSFileBackend.php.

FSFileBackend::doDeleteInternal ( array  $params)
protected
FSFileBackend::doDirectoryExists (   $fullCont,
  $dirRel,
array  $params 
)
protected
FSFileBackend::doExecuteOpHandlesInternal ( array  $fileOpHandles)
protected
Parameters
FSFileOpHandle[]$fileOpHandles
Returns
Status[]

Definition at line 687 of file FSFileBackend.php.

References $status, as, chmod(), and Status\newGood().

FSFileBackend::doGetFileStat ( array  $params)
protected
FSFileBackend::doGetLocalCopyMulti ( array  $params)
protected
FSFileBackend::doGetLocalReferenceMulti ( array  $params)
protected

Definition at line 631 of file FSFileBackend.php.

References $source, as, and resolveToFSPath().

FSFileBackend::doMoveInternal ( array  $params)
protected
FSFileBackend::doPrepareInternal (   $fullCont,
  $dirRel,
array  $params 
)
protected
Parameters
string$fullCont
string$dirRel
array$params
Returns
Status

Definition at line 446 of file FSFileBackend.php.

References $dir, $status, containerFSRoot(), doSecureInternal(), list, Status\newGood(), FileBackend\splitStoragePath(), trapWarnings(), untrapWarnings(), wfDebugLog(), and wfMkdirParents().

FSFileBackend::doPublishInternal (   $fullCont,
  $dirRel,
array  $params 
)
protected
FSFileBackend::doSecureInternal (   $fullCont,
  $dirRel,
array  $params 
)
protected
FSFileBackend::getDirectoryListInternal (   $fullCont,
  $dirRel,
array  $params 
)
See also
FileBackendStore::getDirectoryListInternal()
Parameters
string$fullCont
string$dirRel
array$params
Returns
array|null

Definition at line 588 of file FSFileBackend.php.

References $dir, containerFSRoot(), list, FileBackend\splitStoragePath(), and wfDebug().

FSFileBackend::getFeatures ( )

Definition at line 94 of file FSFileBackend.php.

References FileBackend\ATTR_UNICODE_PATHS, and wfIsWindows().

FSFileBackend::getFileListInternal (   $fullCont,
  $dirRel,
array  $params 
)
See also
FileBackendStore::getFileListInternal()
Parameters
string$fullCont
string$dirRel
array$params
Returns
array|FSFileBackendFileList|null

Definition at line 613 of file FSFileBackend.php.

References $dir, containerFSRoot(), list, FileBackend\splitStoragePath(), and wfDebug().

FSFileBackend::handleWarning (   $errno,
  $errstr 
)
Parameters
int$errno
string$errstr
Returns
bool
Access:
private

Definition at line 783 of file FSFileBackend.php.

References wfDebugLog().

FSFileBackend::htaccessPrivate ( )
protected

Return the text of a .htaccess file to make a directory private.

Returns
string

Definition at line 745 of file FSFileBackend.php.

Referenced by doPublishInternal(), and doSecureInternal().

FSFileBackend::indexHtmlPrivate ( )
protected

Return the text of an index.html file to hide directory listings.

Returns
string

Definition at line 736 of file FSFileBackend.php.

Referenced by doPublishInternal(), and doSecureInternal().

FSFileBackend::isLegalRelPath (   $path)
protected

Sanity check a relative file system path for validity.

Parameters
string$pathNormalized relative path
Returns
bool

Definition at line 116 of file FSFileBackend.php.

References $path, and wfIsWindows().

Referenced by resolveContainerPath().

FSFileBackend::isPathUsableInternal (   $storagePath)

Definition at line 166 of file FSFileBackend.php.

References resolveToFSPath().

FSFileBackend::resolveContainerPath (   $container,
  $relStoragePath 
)
protected

Definition at line 98 of file FSFileBackend.php.

References isLegalRelPath().

FSFileBackend::resolveToFSPath (   $storagePath)
protected

Get the absolute file system path for a storage path.

Parameters
string$storagePathStorage path
Returns
string|null

Definition at line 152 of file FSFileBackend.php.

References containerFSRoot(), list, FileBackendStore\resolveStoragePathReal(), and FileBackend\splitStoragePath().

Referenced by doCopyInternal(), doCreateInternal(), doDeleteInternal(), doGetFileStat(), doGetLocalCopyMulti(), doGetLocalReferenceMulti(), doMoveInternal(), doStoreInternal(), and isPathUsableInternal().

FSFileBackend::trapWarnings ( )
protected
FSFileBackend::untrapWarnings ( )
protected

Member Data Documentation

string FSFileBackend::$basePath
protected

Directory holding the container directories.

Definition at line 43 of file FSFileBackend.php.

array FSFileBackend::$containerPaths = []
protected

Map of container names to root paths for custom container paths.

Definition at line 46 of file FSFileBackend.php.

string FSFileBackend::$currentUser
protected

OS username running this script.

Definition at line 55 of file FSFileBackend.php.

int FSFileBackend::$fileMode
protected

File permission mode.

Definition at line 49 of file FSFileBackend.php.

string FSFileBackend::$fileOwner
protected

Required OS username to own files.

Definition at line 52 of file FSFileBackend.php.

array FSFileBackend::$hadWarningErrors = []
protected

Definition at line 58 of file FSFileBackend.php.


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