mirror of
https://github.com/danog/file.git
synced 2024-11-30 04:19:39 +01:00
Forward global functions to Filesystem
This commit is contained in:
parent
701e1c974e
commit
3983198322
@ -104,7 +104,7 @@ interface Driver
|
|||||||
*
|
*
|
||||||
* @return Promise<void>
|
* @return Promise<void>
|
||||||
*/
|
*/
|
||||||
public function createDirectories(string $path, int $mode = 0777): Promise;
|
public function createDirectoryRecursively(string $path, int $mode = 0777): Promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a directory.
|
* Delete a directory.
|
||||||
|
@ -193,7 +193,7 @@ final class BlockingDriver implements Driver
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createDirectories(string $path, int $mode = 0777): Promise
|
public function createDirectoryRecursively(string $path, int $mode = 0777): Promise
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
\set_error_handler(static function ($type, $message) use ($path) {
|
\set_error_handler(static function ($type, $message) use ($path) {
|
||||||
|
@ -144,7 +144,7 @@ final class EioDriver implements Driver
|
|||||||
return $deferred->promise();
|
return $deferred->promise();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createDirectories(string $path, int $mode = 0777): Promise
|
public function createDirectoryRecursively(string $path, int $mode = 0777): Promise
|
||||||
{
|
{
|
||||||
$deferred = new Deferred;
|
$deferred = new Deferred;
|
||||||
$this->poll->listen($deferred->promise());
|
$this->poll->listen($deferred->promise());
|
||||||
|
@ -90,7 +90,7 @@ final class ParallelDriver implements Driver
|
|||||||
return new Coroutine($this->runFileTask(new Internal\FileTask("createDirectory", [$path, $mode])));
|
return new Coroutine($this->runFileTask(new Internal\FileTask("createDirectory", [$path, $mode])));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createDirectories(string $path, int $mode = 0777): Promise
|
public function createDirectoryRecursively(string $path, int $mode = 0777): Promise
|
||||||
{
|
{
|
||||||
return new Coroutine($this->runFileTask(new Internal\FileTask("createDirectories", [$path, $mode])));
|
return new Coroutine($this->runFileTask(new Internal\FileTask("createDirectories", [$path, $mode])));
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ final class UvDriver implements Driver
|
|||||||
return $deferred->promise();
|
return $deferred->promise();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createDirectories(string $path, int $mode = 0777): Promise
|
public function createDirectoryRecursively(string $path, int $mode = 0777): Promise
|
||||||
{
|
{
|
||||||
$deferred = new Deferred;
|
$deferred = new Deferred;
|
||||||
$this->poll->listen($deferred->promise());
|
$this->poll->listen($deferred->promise());
|
||||||
|
@ -313,9 +313,9 @@ final class Filesystem
|
|||||||
*
|
*
|
||||||
* @return Promise<void>
|
* @return Promise<void>
|
||||||
*/
|
*/
|
||||||
public function createDirectories(string $path, int $mode = 0777): Promise
|
public function createDirectoryRecursively(string $path, int $mode = 0777): Promise
|
||||||
{
|
{
|
||||||
return $this->driver->createDirectories($path, $mode);
|
return $this->driver->createDirectoryRecursively($path, $mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -118,11 +118,7 @@ function getLinkStatus(string $path): Promise
|
|||||||
*/
|
*/
|
||||||
function exists(string $path): Promise
|
function exists(string $path): Promise
|
||||||
{
|
{
|
||||||
return call(static function () use ($path) {
|
return filesystem()->exists($path);
|
||||||
$result = yield getStatus($path);
|
|
||||||
|
|
||||||
return $result !== null;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -138,18 +134,7 @@ function exists(string $path): Promise
|
|||||||
*/
|
*/
|
||||||
function getSize(string $path): Promise
|
function getSize(string $path): Promise
|
||||||
{
|
{
|
||||||
return call(static function () use ($path) {
|
return filesystem()->getSize($path);
|
||||||
$result = yield getStatus($path);
|
|
||||||
if ($result === null) {
|
|
||||||
throw new FilesystemException("Failed to read file size for '{$path}'");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($result['mode'] & 0100000) {
|
|
||||||
return $result["size"];
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new FilesystemException("Failed to read file size for '{$path}'; specified path is not a regular file");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -161,14 +146,7 @@ function getSize(string $path): Promise
|
|||||||
*/
|
*/
|
||||||
function isDirectory(string $path): Promise
|
function isDirectory(string $path): Promise
|
||||||
{
|
{
|
||||||
return call(static function () use ($path) {
|
return filesystem()->isDirectory($path);
|
||||||
$result = yield getStatus($path);
|
|
||||||
if ($result === null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (bool) ($result['mode'] & 0040000);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -180,14 +158,7 @@ function isDirectory(string $path): Promise
|
|||||||
*/
|
*/
|
||||||
function isFile(string $path): Promise
|
function isFile(string $path): Promise
|
||||||
{
|
{
|
||||||
return call(static function () use ($path) {
|
return filesystem()->isFile($path);
|
||||||
$result = yield getStatus($path);
|
|
||||||
if ($result === null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (bool) ($result['mode'] & 0100000);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -202,14 +173,7 @@ function isFile(string $path): Promise
|
|||||||
*/
|
*/
|
||||||
function isSymlink(string $path): Promise
|
function isSymlink(string $path): Promise
|
||||||
{
|
{
|
||||||
return call(function () use ($path) {
|
return filesystem()->isSymlink($path);
|
||||||
$result = yield $this->getLinkStatus($path);
|
|
||||||
if ($result === null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ($result['mode'] & 0120000) === 0120000;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -222,14 +186,7 @@ function isSymlink(string $path): Promise
|
|||||||
*/
|
*/
|
||||||
function getModificationTime(string $path): Promise
|
function getModificationTime(string $path): Promise
|
||||||
{
|
{
|
||||||
return call(static function () use ($path) {
|
return filesystem()->getModificationTime($path);
|
||||||
$result = yield getStatus($path);
|
|
||||||
if ($result === null) {
|
|
||||||
throw new FilesystemException("Failed to read file modification time for '{$path}'");
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result["mtime"];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -242,14 +199,7 @@ function getModificationTime(string $path): Promise
|
|||||||
*/
|
*/
|
||||||
function getAccessTime(string $path): Promise
|
function getAccessTime(string $path): Promise
|
||||||
{
|
{
|
||||||
return call(static function () use ($path) {
|
return filesystem()->getAccessTime($path);
|
||||||
$result = yield getStatus($path);
|
|
||||||
if ($result === null) {
|
|
||||||
throw new FilesystemException("Failed to read file access time for '{$path}'");
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result["atime"];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -262,14 +212,7 @@ function getAccessTime(string $path): Promise
|
|||||||
*/
|
*/
|
||||||
function getCreationTime(string $path): Promise
|
function getCreationTime(string $path): Promise
|
||||||
{
|
{
|
||||||
return call(static function () use ($path) {
|
return filesystem()->getCreationTime($path);
|
||||||
$result = yield getStatus($path);
|
|
||||||
if ($result === null) {
|
|
||||||
throw new FilesystemException("Failed to read file creation time for '{$path}'");
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result["ctime"];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -363,9 +306,9 @@ function createDirectory(string $path, int $mode = 0777): Promise
|
|||||||
*
|
*
|
||||||
* @return Promise<void>
|
* @return Promise<void>
|
||||||
*/
|
*/
|
||||||
function createDirectories(string $path, int $mode = 0777): Promise
|
function createDirectoryRecursively(string $path, int $mode = 0777): Promise
|
||||||
{
|
{
|
||||||
return filesystem()->createDirectories($path, $mode);
|
return filesystem()->createDirectoryRecursively($path, $mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -344,7 +344,7 @@ abstract class DriverTest extends FilesystemTest
|
|||||||
// test for 0, because previous array_filter made that not work
|
// test for 0, because previous array_filter made that not work
|
||||||
$dir = "{$fixtureDir}/newdir/with/recursive/creation/0/1/2";
|
$dir = "{$fixtureDir}/newdir/with/recursive/creation/0/1/2";
|
||||||
|
|
||||||
$this->assertNull(yield $this->driver->createDirectories($dir, 0764));
|
$this->assertNull(yield $this->driver->createDirectoryRecursively($dir, 0764));
|
||||||
$stat = yield $this->driver->getStatus($dir);
|
$stat = yield $this->driver->getStatus($dir);
|
||||||
$this->assertSame('0744', $this->getPermissionsFromStatus($stat));
|
$this->assertSame('0744', $this->getPermissionsFromStatus($stat));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user