Filesystem: added some documentation for createLockFile() and releaseLockFile()

[ci skip]
This commit is contained in:
Dylan T 2019-10-07 10:03:29 +01:00 committed by GitHub
parent 37763685aa
commit d456cb2419
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -91,6 +91,16 @@ final class Filesystem{
return $result;
}
/**
* Attempts to get a lock on the specified file, creating it if it does not exist. This is typically used for IPC to
* inform other processes that some file or folder is already in use, to avoid data corruption.
* If this function succeeds in gaining a lock on the file, it writes the current PID to the file.
*
* @param string $lockFilePath
*
* @return int|null process ID of the process currently holding the lock failure, null on success.
* @throws \InvalidArgumentException if the lock file path is invalid (e.g. parent directory doesn't exist, permission denied)
*/
public static function createLockFile(string $lockFilePath) : ?int{
$resource = fopen($lockFilePath, "a+b");
if($resource === false){
@ -114,6 +124,12 @@ final class Filesystem{
return null;
}
/**
* Releases a file lock previously acquired by createLockFile() and deletes the lock file.
*
* @param string $lockFilePath
* @throws \InvalidArgumentException if the lock file path is invalid (e.g. parent directory doesn't exist, permission denied)
*/
public static function releaseLockFile(string $lockFilePath) : void{
$lockFilePath = realpath($lockFilePath);
if($lockFilePath === false){