2016-12-30 03:59:59 +01:00
|
|
|
<?php
|
2015-07-11 03:59:39 +02:00
|
|
|
|
2015-08-05 16:55:56 +02:00
|
|
|
namespace Amp\File;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
2017-03-17 04:39:49 +01:00
|
|
|
use Amp\Promise;
|
2016-08-24 06:55:06 +02:00
|
|
|
|
2018-10-27 17:57:31 +02:00
|
|
|
interface Driver
|
|
|
|
{
|
2015-08-13 01:02:41 +02:00
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Open a handle for the specified path.
|
2015-08-13 01:02:41 +02:00
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @param string $mode
|
2020-06-24 22:00:24 +02:00
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @return Promise<File>
|
2015-08-13 01:02:41 +02:00
|
|
|
*/
|
2020-06-24 22:00:24 +02:00
|
|
|
public function openFile(string $path, string $mode): Promise;
|
2015-08-13 01:02:41 +02:00
|
|
|
|
2015-07-11 03:59:39 +02:00
|
|
|
/**
|
2020-06-24 22:00:24 +02:00
|
|
|
* Get file status; also known as stat operation.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
|
|
|
* If the requested path does not exist the resulting Promise will resolve to NULL.
|
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @param string $path The file system path to stat.
|
2020-06-24 22:00:24 +02:00
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @return Promise<array|null>
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-06-24 22:00:24 +02:00
|
|
|
public function getStatus(string $path): Promise;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
2020-06-24 22:00:24 +02:00
|
|
|
* Same as {@see Driver::getStatus()} except if the path is a link then the link's data is returned.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
2020-06-30 21:45:09 +02:00
|
|
|
* If the requested path does not exist the resulting Promise will resolve to NULL.
|
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @param string $path The file system path to stat.
|
2020-06-24 22:00:24 +02:00
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @return Promise<array|null> A promise resolving to an associative array upon successful resolution.
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-06-24 22:00:24 +02:00
|
|
|
public function getLinkStatus(string $path): Promise;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Create a symlink $link pointing to the file/directory located at $target.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
|
|
|
* @param string $target
|
|
|
|
* @param string $link
|
2020-06-24 22:00:24 +02:00
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @return Promise<void>
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-06-24 22:00:24 +02:00
|
|
|
public function createSymlink(string $target, string $link): Promise;
|
2017-01-11 14:22:06 +01:00
|
|
|
|
2016-08-24 06:55:06 +02:00
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Create a hard link $link pointing to the file/directory located at $target.
|
2016-08-24 06:55:06 +02:00
|
|
|
*
|
|
|
|
* @param string $target
|
|
|
|
* @param string $link
|
2020-06-24 22:00:24 +02:00
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @return Promise<void>
|
2016-08-24 06:55:06 +02:00
|
|
|
*/
|
2020-06-24 22:00:24 +02:00
|
|
|
public function createHardlink(string $target, string $link): Promise;
|
2017-01-11 14:22:06 +01:00
|
|
|
|
2016-08-24 06:55:06 +02:00
|
|
|
/**
|
2020-06-30 21:45:09 +02:00
|
|
|
* Resolve the symlink at $path.
|
2016-08-24 06:55:06 +02:00
|
|
|
*
|
|
|
|
* @param string $target
|
2020-06-24 22:00:24 +02:00
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @return Promise<string>
|
2016-08-24 06:55:06 +02:00
|
|
|
*/
|
2020-06-24 22:00:24 +02:00
|
|
|
public function resolveSymlink(string $target): Promise;
|
2017-01-11 14:22:06 +01:00
|
|
|
|
2015-07-11 03:59:39 +02:00
|
|
|
/**
|
2020-06-24 22:00:24 +02:00
|
|
|
* Move / rename a file or directory.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
|
|
|
* @param string $from
|
|
|
|
* @param string $to
|
2020-06-24 22:00:24 +02:00
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @return Promise<void>
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-06-24 22:00:24 +02:00
|
|
|
public function move(string $from, string $to): Promise;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Delete a file.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
|
|
|
* @param string $path
|
2020-06-24 22:00:24 +02:00
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @return Promise<void>
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-06-24 22:00:24 +02:00
|
|
|
public function deleteFile(string $path): Promise;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
2020-06-24 22:00:24 +02:00
|
|
|
* Create a directory.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
|
|
|
* @param string $path
|
2020-06-24 22:00:24 +02:00
|
|
|
* @param int $mode
|
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @return Promise<void>
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-06-30 21:45:09 +02:00
|
|
|
public function createDirectory(string $path, int $mode = 0777): Promise;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a directory recursively.
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @param int $mode
|
|
|
|
*
|
|
|
|
* @return Promise<void>
|
|
|
|
*/
|
2020-10-21 21:04:38 +02:00
|
|
|
public function createDirectoryRecursively(string $path, int $mode = 0777): Promise;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Delete a directory.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
|
|
|
* @param string $path
|
2020-06-24 22:00:24 +02:00
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @return Promise<void>
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-06-24 22:00:24 +02:00
|
|
|
public function deleteDirectory(string $path): Promise;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Retrieve an array of files and directories inside the specified path.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
|
|
|
* Dot entries are not included in the resulting array (i.e. "." and "..").
|
|
|
|
*
|
|
|
|
* @param string $path
|
2020-06-24 22:00:24 +02:00
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @return Promise<list<string>>
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-06-24 22:00:24 +02:00
|
|
|
public function listFiles(string $path): Promise;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* chmod a file or directory.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
|
|
|
* @param string $path
|
2020-06-24 22:00:24 +02:00
|
|
|
* @param int $mode
|
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @return Promise<void>
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-06-24 22:00:24 +02:00
|
|
|
public function changePermissions(string $path, int $mode): Promise;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* chown a file or directory.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
2020-06-24 22:00:24 +02:00
|
|
|
* @param string $path
|
2020-06-23 22:40:48 +02:00
|
|
|
* @param int|null $uid
|
|
|
|
* @param int|null $gid
|
2020-06-24 22:00:24 +02:00
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @return Promise<void>
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-06-24 22:00:24 +02:00
|
|
|
public function changeOwner(string $path, ?int $uid, ?int $gid): Promise;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
2015-07-18 20:53:46 +02:00
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Update the access and modification time of the specified path.
|
2015-07-18 20:53:46 +02:00
|
|
|
*
|
|
|
|
* If the file does not exist it will be created automatically.
|
|
|
|
*
|
2020-06-24 22:00:24 +02:00
|
|
|
* @param string $path
|
2020-06-30 21:45:09 +02:00
|
|
|
* @param int|null $modificationTime The touch time. If $time is not supplied, the current system time is used.
|
|
|
|
* @param int|null $accessTime The access time. If $atime is not supplied, value passed to the $time parameter is
|
|
|
|
* used.
|
2020-06-24 22:00:24 +02:00
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @return Promise<void>
|
2015-07-18 20:53:46 +02:00
|
|
|
*/
|
2020-06-30 21:45:09 +02:00
|
|
|
public function touch(string $path, ?int $modificationTime, ?int $accessTime): Promise;
|
2015-07-18 20:53:46 +02:00
|
|
|
|
2015-07-11 03:59:39 +02:00
|
|
|
/**
|
2017-06-17 23:41:57 +02:00
|
|
|
* Buffer the specified file's contents.
|
2015-07-11 03:59:39 +02:00
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @param string $path The file path from which to buffer contents.
|
2020-06-24 22:00:24 +02:00
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @return Promise<string> A promise resolving to a string upon successful resolution.
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-06-24 22:00:24 +02:00
|
|
|
public function read(string $path): Promise;
|
2015-07-11 03:59:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Write the contents string to the specified path.
|
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @param string $path The file path to which to $contents should be written.
|
|
|
|
* @param string $contents The data to write to the specified $path.
|
2020-06-24 22:00:24 +02:00
|
|
|
*
|
2020-06-23 22:40:48 +02:00
|
|
|
* @return Promise<void>
|
2015-07-11 03:59:39 +02:00
|
|
|
*/
|
2020-06-24 22:00:24 +02:00
|
|
|
public function write(string $path, string $contents): Promise;
|
2015-07-11 03:59:39 +02:00
|
|
|
}
|