mirror of
https://github.com/danog/file.git
synced 2024-11-26 11:54:54 +01:00
Fix code style
This commit is contained in:
parent
7a96e10a35
commit
62428ca0ef
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,3 +1,3 @@
|
|||||||
composer.lock
|
/composer.lock
|
||||||
vendor/
|
/vendor
|
||||||
.idea
|
/.php_cs.cache
|
15
.php_cs
15
.php_cs
@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
return Symfony\CS\Config\Config::create()
|
|
||||||
->level(Symfony\CS\FixerInterface::NONE_LEVEL)
|
|
||||||
->fixers([
|
|
||||||
"psr2",
|
|
||||||
"-braces",
|
|
||||||
"-psr0",
|
|
||||||
])
|
|
||||||
->finder(
|
|
||||||
Symfony\CS\Finder\DefaultFinder::create()
|
|
||||||
->in(__DIR__ . "/lib")
|
|
||||||
->in(__DIR__ . "/test")
|
|
||||||
)
|
|
||||||
;
|
|
39
.php_cs.dist
Normal file
39
.php_cs.dist
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return PhpCsFixer\Config::create()
|
||||||
|
->setRiskyAllowed(true)
|
||||||
|
->setRules([
|
||||||
|
"@PSR1" => true,
|
||||||
|
"@PSR2" => true,
|
||||||
|
"braces" => [
|
||||||
|
"allow_single_line_closure" => true,
|
||||||
|
"position_after_functions_and_oop_constructs" => "same",
|
||||||
|
],
|
||||||
|
"array_syntax" => ["syntax" => "short"],
|
||||||
|
"cast_spaces" => true,
|
||||||
|
"combine_consecutive_unsets" => true,
|
||||||
|
"function_to_constant" => true,
|
||||||
|
"no_multiline_whitespace_before_semicolons" => true,
|
||||||
|
"no_unused_imports" => true,
|
||||||
|
"no_useless_else" => true,
|
||||||
|
"no_useless_return" => true,
|
||||||
|
"no_whitespace_before_comma_in_array" => true,
|
||||||
|
"no_whitespace_in_blank_line" => true,
|
||||||
|
"non_printable_character" => true,
|
||||||
|
"normalize_index_brace" => true,
|
||||||
|
"ordered_imports" => true,
|
||||||
|
"php_unit_construct" => true,
|
||||||
|
"php_unit_dedicate_assert" => true,
|
||||||
|
"php_unit_fqcn_annotation" => true,
|
||||||
|
"phpdoc_summary" => true,
|
||||||
|
"phpdoc_types" => true,
|
||||||
|
"psr4" => true,
|
||||||
|
"return_type_declaration" => ["space_before" => "none"],
|
||||||
|
"short_scalar_cast" => true,
|
||||||
|
"single_blank_line_before_namespace" => true,
|
||||||
|
])
|
||||||
|
->setFinder(
|
||||||
|
PhpCsFixer\Finder::create()
|
||||||
|
->in(__DIR__ . "/lib")
|
||||||
|
->in(__DIR__ . "/test")
|
||||||
|
);
|
45
Makefile
Normal file
45
Makefile
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
PHP_BIN := php
|
||||||
|
COMPOSER_BIN := composer
|
||||||
|
|
||||||
|
COVERAGE = coverage
|
||||||
|
SRCS = lib test
|
||||||
|
|
||||||
|
find_php_files = $(shell find $(1) -type f -name "*.php")
|
||||||
|
src = $(foreach d,$(SRCS),$(call find_php_files,$(d)))
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
test: setup phpunit code-style
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean: clean-coverage clean-vendor
|
||||||
|
|
||||||
|
.PHONY: clean-coverage
|
||||||
|
clean-coverage:
|
||||||
|
test ! -e coverage || rm -r coverage
|
||||||
|
|
||||||
|
.PHONY: clean-vendor
|
||||||
|
clean-vendor:
|
||||||
|
test ! -e vendor || rm -r vendor
|
||||||
|
|
||||||
|
.PHONY: setup
|
||||||
|
setup: vendor/autoload.php
|
||||||
|
|
||||||
|
.PHONY: deps-update
|
||||||
|
deps-update:
|
||||||
|
$(COMPOSER_BIN) update
|
||||||
|
|
||||||
|
.PHONY: phpunit
|
||||||
|
phpunit: setup
|
||||||
|
$(PHP_BIN) vendor/bin/phpunit
|
||||||
|
|
||||||
|
.PHONY: code-style
|
||||||
|
code-style: setup
|
||||||
|
PHP_CS_FIXER_IGNORE_ENV=1 $(PHP_BIN) vendor/bin/php-cs-fixer --diff -v fix
|
||||||
|
|
||||||
|
composer.lock: composer.json
|
||||||
|
$(COMPOSER_BIN) install
|
||||||
|
touch $@
|
||||||
|
|
||||||
|
vendor/autoload.php: composer.lock
|
||||||
|
$(COMPOSER_BIN) install
|
||||||
|
touch $@
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace Amp\File;
|
namespace Amp\File;
|
||||||
|
|
||||||
use Amp\{ Success, Failure, Promise };
|
use Amp\Failure;
|
||||||
|
use Amp\Promise;
|
||||||
|
use Amp\Success;
|
||||||
|
|
||||||
class BlockingDriver implements Driver {
|
class BlockingDriver implements Driver {
|
||||||
/**
|
/**
|
||||||
@ -41,6 +43,7 @@ class BlockingDriver implements Driver {
|
|||||||
if ($exists = @\file_exists($path)) {
|
if ($exists = @\file_exists($path)) {
|
||||||
\clearstatcache(true, $path);
|
\clearstatcache(true, $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Success($exists);
|
return new Success($exists);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,18 +61,22 @@ class BlockingDriver implements Driver {
|
|||||||
return new Failure(new FilesystemException(
|
return new Failure(new FilesystemException(
|
||||||
"Path does not exist"
|
"Path does not exist"
|
||||||
));
|
));
|
||||||
} elseif (!@\is_file($path)) {
|
}
|
||||||
|
|
||||||
|
if (!@\is_file($path)) {
|
||||||
return new Failure(new FilesystemException(
|
return new Failure(new FilesystemException(
|
||||||
"Path is not a regular file"
|
"Path is not a regular file"
|
||||||
));
|
));
|
||||||
} elseif (($size = @\filesize($path)) === false) {
|
}
|
||||||
|
|
||||||
|
if (($size = @\filesize($path)) === false) {
|
||||||
return new Failure(new FilesystemException(
|
return new Failure(new FilesystemException(
|
||||||
\error_get_last()["message"]
|
\error_get_last()["message"]
|
||||||
));
|
));
|
||||||
} else {
|
|
||||||
\clearstatcache(true, $path);
|
|
||||||
return new Success($size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
\clearstatcache(true, $path);
|
||||||
|
return new Success($size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -85,6 +92,7 @@ class BlockingDriver implements Driver {
|
|||||||
if (!@\file_exists($path)) {
|
if (!@\file_exists($path)) {
|
||||||
return new Success(false);
|
return new Success(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
$isDir = @\is_dir($path);
|
$isDir = @\is_dir($path);
|
||||||
\clearstatcache(true, $path);
|
\clearstatcache(true, $path);
|
||||||
|
|
||||||
@ -104,6 +112,7 @@ class BlockingDriver implements Driver {
|
|||||||
if (!@\file_exists($path)) {
|
if (!@\file_exists($path)) {
|
||||||
return new Success(false);
|
return new Success(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
$isFile = @\is_file($path);
|
$isFile = @\is_file($path);
|
||||||
\clearstatcache(true, $path);
|
\clearstatcache(true, $path);
|
||||||
|
|
||||||
@ -111,7 +120,7 @@ class BlockingDriver implements Driver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the path's last modification time as a unix timestamp
|
* Retrieve the path's last modification time as a unix timestamp.
|
||||||
*
|
*
|
||||||
* @param string $path An absolute file system path
|
* @param string $path An absolute file system path
|
||||||
* @return \Amp\Promise<int>
|
* @return \Amp\Promise<int>
|
||||||
@ -122,6 +131,7 @@ class BlockingDriver implements Driver {
|
|||||||
"Path does not exist"
|
"Path does not exist"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$mtime = @\filemtime($path);
|
$mtime = @\filemtime($path);
|
||||||
\clearstatcache(true, $path);
|
\clearstatcache(true, $path);
|
||||||
|
|
||||||
@ -129,7 +139,7 @@ class BlockingDriver implements Driver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the path's last access time as a unix timestamp
|
* Retrieve the path's last access time as a unix timestamp.
|
||||||
*
|
*
|
||||||
* @param string $path An absolute file system path
|
* @param string $path An absolute file system path
|
||||||
* @return \Amp\Promise<int>
|
* @return \Amp\Promise<int>
|
||||||
@ -147,7 +157,7 @@ class BlockingDriver implements Driver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the path's creation time as a unix timestamp
|
* Retrieve the path's creation time as a unix timestamp.
|
||||||
*
|
*
|
||||||
* @param string $path An absolute file system path
|
* @param string $path An absolute file system path
|
||||||
* @return \Amp\Promise<int>
|
* @return \Amp\Promise<int>
|
||||||
@ -158,6 +168,7 @@ class BlockingDriver implements Driver {
|
|||||||
"Path does not exist"
|
"Path does not exist"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$ctime = @\filectime($path);
|
$ctime = @\filectime($path);
|
||||||
\clearstatcache(true, $path);
|
\clearstatcache(true, $path);
|
||||||
|
|
||||||
@ -253,16 +264,16 @@ class BlockingDriver implements Driver {
|
|||||||
"Not a directory"
|
"Not a directory"
|
||||||
));
|
));
|
||||||
} elseif ($arr = @\scandir($path)) {
|
} elseif ($arr = @\scandir($path)) {
|
||||||
$arr = \array_values(\array_filter($arr, function($el) {
|
$arr = \array_values(\array_filter($arr, function ($el) {
|
||||||
return !($el === "." || $el === "..");
|
return !($el === "." || $el === "..");
|
||||||
}));
|
}));
|
||||||
\clearstatcache(true, $path);
|
\clearstatcache(true, $path);
|
||||||
return new Success($arr);
|
return new Success($arr);
|
||||||
} else {
|
|
||||||
return new Failure(new FilesystemException(
|
|
||||||
"Failed reading contents from {$path}"
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new Failure(new FilesystemException(
|
||||||
|
"Failed reading contents from {$path}"
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -305,8 +316,7 @@ class BlockingDriver implements Driver {
|
|||||||
$result = @\file_get_contents($path);
|
$result = @\file_get_contents($path);
|
||||||
return ($result === false)
|
return ($result === false)
|
||||||
? new Failure(new FilesystemException(\error_get_last()["message"]))
|
? new Failure(new FilesystemException(\error_get_last()["message"]))
|
||||||
: new Success($result)
|
: new Success($result);
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -316,7 +326,6 @@ class BlockingDriver implements Driver {
|
|||||||
$result = @\file_put_contents($path, $contents);
|
$result = @\file_put_contents($path, $contents);
|
||||||
return ($result === false)
|
return ($result === false)
|
||||||
? new Failure(new FilesystemException(\error_get_last()["message"]))
|
? new Failure(new FilesystemException(\error_get_last()["message"]))
|
||||||
: new Success($result)
|
: new Success($result);
|
||||||
;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace Amp\File;
|
namespace Amp\File;
|
||||||
|
|
||||||
use Amp\{ Success, Failure, Promise };
|
use Amp\Failure;
|
||||||
|
use Amp\Promise;
|
||||||
|
use Amp\Success;
|
||||||
|
|
||||||
class BlockingHandle implements Handle {
|
class BlockingHandle implements Handle {
|
||||||
private $fh;
|
private $fh;
|
||||||
@ -35,13 +37,14 @@ class BlockingHandle implements Handle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$data = \fread($this->fh, $length);
|
$data = \fread($this->fh, $length);
|
||||||
|
|
||||||
if ($data !== false) {
|
if ($data !== false) {
|
||||||
return new Success(\strlen($data) ? $data : null);
|
return new Success(\strlen($data) ? $data : null);
|
||||||
} else {
|
|
||||||
return new Failure(new FilesystemException(
|
|
||||||
"Failed reading from file handle"
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new Failure(new FilesystemException(
|
||||||
|
"Failed reading from file handle"
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,13 +56,14 @@ class BlockingHandle implements Handle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$len = \fwrite($this->fh, $data);
|
$len = \fwrite($this->fh, $data);
|
||||||
|
|
||||||
if ($len !== false) {
|
if ($len !== false) {
|
||||||
return new Success($len);
|
return new Success($len);
|
||||||
} else {
|
|
||||||
return new Failure(new FilesystemException(
|
|
||||||
"Failed writing to file handle"
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new Failure(new FilesystemException(
|
||||||
|
"Failed writing to file handle"
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,11 +88,11 @@ class BlockingHandle implements Handle {
|
|||||||
|
|
||||||
if (@\fclose($fh)) {
|
if (@\fclose($fh)) {
|
||||||
return new Success;
|
return new Success;
|
||||||
} else {
|
|
||||||
return new Failure(new FilesystemException(
|
|
||||||
"Failed closing file handle"
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new Failure(new FilesystemException(
|
||||||
|
"Failed closing file handle"
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,7 +6,7 @@ use Amp\Promise;
|
|||||||
|
|
||||||
interface Driver {
|
interface Driver {
|
||||||
/**
|
/**
|
||||||
* Open a handle for the specified path
|
* Open a handle for the specified path.
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param string $mode
|
* @param string $mode
|
||||||
@ -15,7 +15,7 @@ interface Driver {
|
|||||||
public function open(string $path, string $mode): Promise;
|
public function open(string $path, string $mode): Promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute a file stat operation
|
* Execute a file stat operation.
|
||||||
*
|
*
|
||||||
* If the requested path does not exist the resulting Promise will resolve to NULL.
|
* If the requested path does not exist the resulting Promise will resolve to NULL.
|
||||||
*
|
*
|
||||||
@ -69,7 +69,7 @@ interface Driver {
|
|||||||
public function isfile(string $path): Promise;
|
public function isfile(string $path): Promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the path's last modification time as a unix timestamp
|
* Retrieve the path's last modification time as a unix timestamp.
|
||||||
*
|
*
|
||||||
* @param string $path An absolute file system path
|
* @param string $path An absolute file system path
|
||||||
* @return \Amp\Promise<int>
|
* @return \Amp\Promise<int>
|
||||||
@ -77,7 +77,7 @@ interface Driver {
|
|||||||
public function mtime(string $path): Promise;
|
public function mtime(string $path): Promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the path's last access time as a unix timestamp
|
* Retrieve the path's last access time as a unix timestamp.
|
||||||
*
|
*
|
||||||
* @param string $path An absolute file system path
|
* @param string $path An absolute file system path
|
||||||
* @return \Amp\Promise<int>
|
* @return \Amp\Promise<int>
|
||||||
@ -85,7 +85,7 @@ interface Driver {
|
|||||||
public function atime(string $path): Promise;
|
public function atime(string $path): Promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the path's creation time as a unix timestamp
|
* Retrieve the path's creation time as a unix timestamp.
|
||||||
*
|
*
|
||||||
* @param string $path An absolute file system path
|
* @param string $path An absolute file system path
|
||||||
* @return \Amp\Promise<int>
|
* @return \Amp\Promise<int>
|
||||||
@ -93,7 +93,7 @@ interface Driver {
|
|||||||
public function ctime(string $path): Promise;
|
public function ctime(string $path): Promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Same as stat() except if the path is a link then the link's data is returned
|
* Same as stat() except if the path is a link then the link's data is returned.
|
||||||
*
|
*
|
||||||
* @param string $path The file system path to stat
|
* @param string $path The file system path to stat
|
||||||
* @return \Amp\Promise A promise resolving to an associative array upon successful resolution
|
* @return \Amp\Promise A promise resolving to an associative array upon successful resolution
|
||||||
@ -101,7 +101,7 @@ interface Driver {
|
|||||||
public function lstat(string $path): Promise;
|
public function lstat(string $path): Promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a symlink $link pointing to the file/directory located at $target
|
* Create a symlink $link pointing to the file/directory located at $target.
|
||||||
*
|
*
|
||||||
* @param string $target
|
* @param string $target
|
||||||
* @param string $link
|
* @param string $link
|
||||||
@ -110,7 +110,7 @@ interface Driver {
|
|||||||
public function symlink(string $target, string $link): Promise;
|
public function symlink(string $target, string $link): Promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a hard link $link pointing to the file/directory located at $target
|
* Create a hard link $link pointing to the file/directory located at $target.
|
||||||
*
|
*
|
||||||
* @param string $target
|
* @param string $target
|
||||||
* @param string $link
|
* @param string $link
|
||||||
@ -127,7 +127,7 @@ interface Driver {
|
|||||||
public function readlink(string $target): Promise;
|
public function readlink(string $target): Promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rename a file or directory
|
* Rename a file or directory.
|
||||||
*
|
*
|
||||||
* @param string $from
|
* @param string $from
|
||||||
* @param string $to
|
* @param string $to
|
||||||
@ -136,7 +136,7 @@ interface Driver {
|
|||||||
public function rename(string $from, string $to): Promise;
|
public function rename(string $from, string $to): Promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a file
|
* Delete a file.
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @return \Amp\Promise
|
* @return \Amp\Promise
|
||||||
@ -144,7 +144,7 @@ interface Driver {
|
|||||||
public function unlink(string $path): Promise;
|
public function unlink(string $path): Promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a director
|
* Create a director.
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param int $mode
|
* @param int $mode
|
||||||
@ -154,7 +154,7 @@ interface Driver {
|
|||||||
public function mkdir(string $path, int $mode = 0644, bool $recursive = false): Promise;
|
public function mkdir(string $path, int $mode = 0644, bool $recursive = false): Promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a directory
|
* Delete a directory.
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @return \Amp\Promise
|
* @return \Amp\Promise
|
||||||
@ -162,7 +162,7 @@ interface Driver {
|
|||||||
public function rmdir(string $path): Promise;
|
public function rmdir(string $path): Promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve an array of files and directories inside the specified path
|
* Retrieve an array of files and directories inside the specified path.
|
||||||
*
|
*
|
||||||
* Dot entries are not included in the resulting array (i.e. "." and "..").
|
* Dot entries are not included in the resulting array (i.e. "." and "..").
|
||||||
*
|
*
|
||||||
@ -172,7 +172,7 @@ interface Driver {
|
|||||||
public function scandir(string $path): Promise;
|
public function scandir(string $path): Promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* chmod a file or directory
|
* chmod a file or directory.
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param int $mode
|
* @param int $mode
|
||||||
@ -181,7 +181,7 @@ interface Driver {
|
|||||||
public function chmod(string $path, int $mode): Promise;
|
public function chmod(string $path, int $mode): Promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* chown a file or directory
|
* chown a file or directory.
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param int $uid
|
* @param int $uid
|
||||||
@ -191,7 +191,7 @@ interface Driver {
|
|||||||
public function chown(string $path, int $uid, int $gid): Promise;
|
public function chown(string $path, int $uid, int $gid): Promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the access and modification time of the specified path
|
* Update the access and modification time of the specified path.
|
||||||
*
|
*
|
||||||
* If the file does not exist it will be created automatically.
|
* If the file does not exist it will be created automatically.
|
||||||
*
|
*
|
||||||
@ -201,7 +201,7 @@ interface Driver {
|
|||||||
public function touch(string $path): Promise;
|
public function touch(string $path): Promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Buffer the specified file's contents
|
* Buffer the specified file's contents.
|
||||||
*
|
*
|
||||||
* @param string $path The file path from which to buffer contents
|
* @param string $path The file path from which to buffer contents
|
||||||
* @return \Amp\Promise A promise resolving to a string upon successful resolution
|
* @return \Amp\Promise A promise resolving to a string upon successful resolution
|
||||||
|
@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
namespace Amp\File;
|
namespace Amp\File;
|
||||||
|
|
||||||
use Amp\{ Deferred, Loop, Promise, Success };
|
use Amp\Deferred;
|
||||||
|
use Amp\Loop;
|
||||||
|
use Amp\Promise;
|
||||||
|
use Amp\Success;
|
||||||
|
|
||||||
class EioDriver implements Driver {
|
class EioDriver implements Driver {
|
||||||
private $watcher;
|
private $watcher;
|
||||||
@ -22,7 +25,7 @@ class EioDriver implements Driver {
|
|||||||
\eio_init();
|
\eio_init();
|
||||||
self::$stream = \eio_get_event_stream();
|
self::$stream = \eio_get_event_stream();
|
||||||
}
|
}
|
||||||
$this->callableDecrementor = function() {
|
$this->callableDecrementor = function () {
|
||||||
($this->incrementor)(-1);
|
($this->incrementor)(-1);
|
||||||
};
|
};
|
||||||
$this->incrementor = function ($increment) {
|
$this->incrementor = function ($increment) {
|
||||||
@ -390,11 +393,11 @@ class EioDriver implements Driver {
|
|||||||
$priority = \EIO_PRI_DEFAULT;
|
$priority = \EIO_PRI_DEFAULT;
|
||||||
|
|
||||||
if ($recursive) {
|
if ($recursive) {
|
||||||
$path = str_replace("/", DIRECTORY_SEPARATOR, $path);
|
$path = str_replace("/", DIRECTORY_SEPARATOR, $path);
|
||||||
$arrayPath = array_filter(explode(DIRECTORY_SEPARATOR, $path));
|
$arrayPath = array_filter(explode(DIRECTORY_SEPARATOR, $path));
|
||||||
$tmpPath = "";
|
$tmpPath = "";
|
||||||
|
|
||||||
$callback = function() use (
|
$callback = function () use (
|
||||||
&$callback, &$arrayPath, &$tmpPath, $mode, $priority, $deferred
|
&$callback, &$arrayPath, &$tmpPath, $mode, $priority, $deferred
|
||||||
) {
|
) {
|
||||||
$tmpPath .= DIRECTORY_SEPARATOR . array_shift($arrayPath);
|
$tmpPath .= DIRECTORY_SEPARATOR . array_shift($arrayPath);
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace Amp\File;
|
namespace Amp\File;
|
||||||
|
|
||||||
use Amp\{ Deferred, Promise, Success };
|
use Amp\Deferred;
|
||||||
|
use Amp\Promise;
|
||||||
|
use Amp\Success;
|
||||||
|
|
||||||
class EioHandle implements Handle {
|
class EioHandle implements Handle {
|
||||||
const OP_READ = 1;
|
const OP_READ = 1;
|
||||||
|
@ -10,7 +10,7 @@ interface Handle extends InputStream, OutputStream {
|
|||||||
const DEFAULT_READ_LENGTH = 8192;
|
const DEFAULT_READ_LENGTH = 8192;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read $len bytes from the open file handle starting at $offset
|
* Read $len bytes from the open file handle starting at $offset.
|
||||||
*
|
*
|
||||||
* @param int $length
|
* @param int $length
|
||||||
* @return \Amp\Promise<string|null>
|
* @return \Amp\Promise<string|null>
|
||||||
@ -18,7 +18,7 @@ interface Handle extends InputStream, OutputStream {
|
|||||||
public function read(int $length = self::DEFAULT_READ_LENGTH): Promise;
|
public function read(int $length = self::DEFAULT_READ_LENGTH): Promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write $data to the open file handle starting at $offset
|
* Write $data to the open file handle starting at $offset.
|
||||||
*
|
*
|
||||||
* @param string $data
|
* @param string $data
|
||||||
* @return \Amp\Promise<int>
|
* @return \Amp\Promise<int>
|
||||||
@ -35,7 +35,7 @@ interface Handle extends InputStream, OutputStream {
|
|||||||
public function end(string $data = ""): Promise;
|
public function end(string $data = ""): Promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close the file handle
|
* Close the file handle.
|
||||||
*
|
*
|
||||||
* Applications are not required to manually close handles -- they will
|
* Applications are not required to manually close handles -- they will
|
||||||
* be unloaded automatically when the object is garbage collected.
|
* be unloaded automatically when the object is garbage collected.
|
||||||
@ -45,7 +45,7 @@ interface Handle extends InputStream, OutputStream {
|
|||||||
public function close(): Promise;
|
public function close(): Promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the handle's internal pointer position
|
* Set the handle's internal pointer position.
|
||||||
*
|
*
|
||||||
* $whence values:
|
* $whence values:
|
||||||
*
|
*
|
||||||
@ -60,28 +60,28 @@ interface Handle extends InputStream, OutputStream {
|
|||||||
public function seek(int $position, int $whence = \SEEK_SET): Promise;
|
public function seek(int $position, int $whence = \SEEK_SET): Promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the current internal offset position of the file handle
|
* Return the current internal offset position of the file handle.
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function tell(): int;
|
public function tell(): int;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for "end-of-file" on the file handle
|
* Test for "end-of-file" on the file handle.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function eof(): bool;
|
public function eof(): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the path used when opening the file handle
|
* Retrieve the path used when opening the file handle.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function path(): string;
|
public function path(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the mode used when opening the file handle
|
* Retrieve the mode used when opening the file handle.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Amp\File\Internal;
|
namespace Amp\File\Internal;
|
||||||
|
|
||||||
use Amp\File\{ BlockingDriver, BlockingHandle, FilesystemException };
|
use Amp\File\BlockingDriver;
|
||||||
use Amp\Parallel\Worker\{ Environment, Task };
|
use Amp\File\BlockingHandle;
|
||||||
|
use Amp\File\FilesystemException;
|
||||||
|
use Amp\Parallel\Worker\Environment;
|
||||||
|
use Amp\Parallel\Worker\Task;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
@ -11,7 +14,7 @@ use Amp\Parallel\Worker\{ Environment, Task };
|
|||||||
*/
|
*/
|
||||||
class FileTask extends BlockingDriver implements Task {
|
class FileTask extends BlockingDriver implements Task {
|
||||||
const ENV_PREFIX = self::class . '_';
|
const ENV_PREFIX = self::class . '_';
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $operation;
|
private $operation;
|
||||||
|
|
||||||
@ -52,7 +55,7 @@ class FileTask extends BlockingDriver implements Task {
|
|||||||
if ("fopen" === $this->operation) {
|
if ("fopen" === $this->operation) {
|
||||||
$path = $this->args[0];
|
$path = $this->args[0];
|
||||||
$mode = \str_replace(['b', 't'], '', $this->args[1]);
|
$mode = \str_replace(['b', 't'], '', $this->args[1]);
|
||||||
|
|
||||||
switch ($mode) {
|
switch ($mode) {
|
||||||
case "r":
|
case "r":
|
||||||
case "r+":
|
case "r+":
|
||||||
@ -65,13 +68,13 @@ class FileTask extends BlockingDriver implements Task {
|
|||||||
case "c":
|
case "c":
|
||||||
case "c+":
|
case "c+":
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new FilesystemException("Invalid file mode");
|
throw new FilesystemException("Invalid file mode");
|
||||||
}
|
}
|
||||||
|
|
||||||
$handle = @\fopen($path, $mode . 'b');
|
$handle = @\fopen($path, $mode . 'b');
|
||||||
|
|
||||||
if (!$handle) {
|
if (!$handle) {
|
||||||
$message = 'Could not open the file.';
|
$message = 'Could not open the file.';
|
||||||
if ($error = \error_get_last()) {
|
if ($error = \error_get_last()) {
|
||||||
@ -79,12 +82,12 @@ class FileTask extends BlockingDriver implements Task {
|
|||||||
}
|
}
|
||||||
throw new FilesystemException($message);
|
throw new FilesystemException($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = new BlockingHandle($handle, $path, $mode);
|
$file = new BlockingHandle($handle, $path, $mode);
|
||||||
$id = (int) $handle;
|
$id = (int) $handle;
|
||||||
$size = \fstat($handle)["size"];
|
$size = \fstat($handle)["size"];
|
||||||
$environment->set($this->makeId($id), $file);
|
$environment->set($this->makeId($id), $file);
|
||||||
|
|
||||||
return [$id, $size, $mode];
|
return [$id, $size, $mode];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,9 +2,13 @@
|
|||||||
|
|
||||||
namespace Amp\File;
|
namespace Amp\File;
|
||||||
|
|
||||||
use Amp\{ Coroutine, Deferred, Promise };
|
use Amp\Coroutine;
|
||||||
|
use Amp\Deferred;
|
||||||
use Amp\Parallel\Worker;
|
use Amp\Parallel\Worker;
|
||||||
use Amp\Parallel\Worker\{ Pool, TaskException, WorkerException };
|
use Amp\Parallel\Worker\Pool;
|
||||||
|
use Amp\Parallel\Worker\TaskException;
|
||||||
|
use Amp\Parallel\Worker\WorkerException;
|
||||||
|
use Amp\Promise;
|
||||||
|
|
||||||
class ParallelDriver implements Driver {
|
class ParallelDriver implements Driver {
|
||||||
/**
|
/**
|
||||||
@ -211,4 +215,5 @@ class ParallelDriver implements Driver {
|
|||||||
*/
|
*/
|
||||||
public function put(string $path, string $contents): Promise {
|
public function put(string $path, string $contents): Promise {
|
||||||
return new Coroutine($this->runFileTask(new Internal\FileTask("put", [$path, $contents])));
|
return new Coroutine($this->runFileTask(new Internal\FileTask("put", [$path, $contents])));
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
|
@ -2,8 +2,12 @@
|
|||||||
|
|
||||||
namespace Amp\File;
|
namespace Amp\File;
|
||||||
|
|
||||||
use Amp\{ Coroutine, Promise, Success };
|
use Amp\Coroutine;
|
||||||
use Amp\Parallel\Worker\{ TaskException, Worker, WorkerException };
|
use Amp\Parallel\Worker\TaskException;
|
||||||
|
use Amp\Parallel\Worker\Worker;
|
||||||
|
use Amp\Parallel\Worker\WorkerException;
|
||||||
|
use Amp\Promise;
|
||||||
|
use Amp\Success;
|
||||||
|
|
||||||
class ParallelHandle implements Handle {
|
class ParallelHandle implements Handle {
|
||||||
/** @var \Amp\Parallel\Worker\Worker */
|
/** @var \Amp\Parallel\Worker\Worker */
|
||||||
|
@ -2,7 +2,11 @@
|
|||||||
|
|
||||||
namespace Amp\File;
|
namespace Amp\File;
|
||||||
|
|
||||||
use Amp\{ Coroutine, Deferred, Loop, Promise, Success };
|
use Amp\Coroutine;
|
||||||
|
use Amp\Deferred;
|
||||||
|
use Amp\Loop;
|
||||||
|
use Amp\Promise;
|
||||||
|
use Amp\Success;
|
||||||
|
|
||||||
class UvDriver implements Driver {
|
class UvDriver implements Driver {
|
||||||
/** @var \Amp\Loop\Driver */
|
/** @var \Amp\Loop\Driver */
|
||||||
@ -22,7 +26,7 @@ class UvDriver implements Driver {
|
|||||||
$this->loop = $driver->getHandle();
|
$this->loop = $driver->getHandle();
|
||||||
|
|
||||||
// dummy handle to be able to tell the loop that there is work being done and it shouldn't abort if there are no other watchers at a given moment
|
// dummy handle to be able to tell the loop that there is work being done and it shouldn't abort if there are no other watchers at a given moment
|
||||||
$this->busy = $driver->repeat(PHP_INT_MAX, function(){ });
|
$this->busy = $driver->repeat(PHP_INT_MAX, function () { });
|
||||||
$driver->unreference($this->busy);
|
$driver->unreference($this->busy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +45,7 @@ class UvDriver implements Driver {
|
|||||||
$this->onOpenHandle($fh, $openArr);
|
$this->onOpenHandle($fh, $openArr);
|
||||||
} else {
|
} else {
|
||||||
$this->driver->unreference($this->busy);
|
$this->driver->unreference($this->busy);
|
||||||
list( , $path, $deferred) = $openArr;
|
list(, $path, $deferred) = $openArr;
|
||||||
$deferred->fail(new FilesystemException(
|
$deferred->fail(new FilesystemException(
|
||||||
"Failed opening file handle to $path"
|
"Failed opening file handle to $path"
|
||||||
));
|
));
|
||||||
@ -79,20 +83,20 @@ class UvDriver implements Driver {
|
|||||||
if ($fh) {
|
if ($fh) {
|
||||||
$this->finalizeHandle($fh, $size = 0, $openArr);
|
$this->finalizeHandle($fh, $size = 0, $openArr);
|
||||||
} else {
|
} else {
|
||||||
list( , $path, $deferred) = $openArr;
|
list(, $path, $deferred) = $openArr;
|
||||||
$deferred->fail(new FilesystemException(
|
$deferred->fail(new FilesystemException(
|
||||||
"Failed truncating file $path"
|
"Failed truncating file $path"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
\uv_fs_fstat($this->loop, $fh, function($fh, $stat) use ($openArr) {
|
\uv_fs_fstat($this->loop, $fh, function ($fh, $stat) use ($openArr) {
|
||||||
$this->driver->unreference($this->busy);
|
$this->driver->unreference($this->busy);
|
||||||
if ($fh) {
|
if ($fh) {
|
||||||
StatCache::set($openArr[1], $stat);
|
StatCache::set($openArr[1], $stat);
|
||||||
$this->finalizeHandle($fh, $stat["size"], $openArr);
|
$this->finalizeHandle($fh, $stat["size"], $openArr);
|
||||||
} else {
|
} else {
|
||||||
list( , $path, $deferred) = $openArr;
|
list(, $path, $deferred) = $openArr;
|
||||||
$deferred->fail(new FilesystemException(
|
$deferred->fail(new FilesystemException(
|
||||||
"Failed reading file size from open handle pointing to $path"
|
"Failed reading file size from open handle pointing to $path"
|
||||||
));
|
));
|
||||||
@ -117,7 +121,7 @@ class UvDriver implements Driver {
|
|||||||
|
|
||||||
$this->driver->reference($this->busy);
|
$this->driver->reference($this->busy);
|
||||||
$deferred = new Deferred;
|
$deferred = new Deferred;
|
||||||
\uv_fs_stat($this->loop, $path, function($fh, $stat) use ($deferred, $path) {
|
\uv_fs_stat($this->loop, $path, function ($fh, $stat) use ($deferred, $path) {
|
||||||
if (empty($fh)) {
|
if (empty($fh)) {
|
||||||
$stat = null;
|
$stat = null;
|
||||||
} else {
|
} else {
|
||||||
@ -256,7 +260,7 @@ class UvDriver implements Driver {
|
|||||||
public function lstat(string $path): Promise {
|
public function lstat(string $path): Promise {
|
||||||
$this->driver->reference($this->busy);
|
$this->driver->reference($this->busy);
|
||||||
$deferred = new Deferred;
|
$deferred = new Deferred;
|
||||||
\uv_fs_lstat($this->loop, $path, function($fh, $stat) use ($deferred) {
|
\uv_fs_lstat($this->loop, $path, function ($fh, $stat) use ($deferred) {
|
||||||
if (empty($fh)) {
|
if (empty($fh)) {
|
||||||
$stat = null;
|
$stat = null;
|
||||||
}
|
}
|
||||||
@ -347,7 +351,7 @@ class UvDriver implements Driver {
|
|||||||
$deferred = new Deferred;
|
$deferred = new Deferred;
|
||||||
|
|
||||||
if ($recursive) {
|
if ($recursive) {
|
||||||
$path = str_replace("/", DIRECTORY_SEPARATOR, $path);
|
$path = str_replace("/", DIRECTORY_SEPARATOR, $path);
|
||||||
$arrayPath = array_filter(explode(DIRECTORY_SEPARATOR, $path));
|
$arrayPath = array_filter(explode(DIRECTORY_SEPARATOR, $path));
|
||||||
$tmpPath = "";
|
$tmpPath = "";
|
||||||
|
|
||||||
@ -498,7 +502,7 @@ class UvDriver implements Driver {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$buffer = (yield $this->doFsRead($fh, $offset = 0, $stat["size"]));
|
$buffer = (yield $this->doFsRead($fh, $offset = 0, $stat["size"]));
|
||||||
if ($buffer === false ) {
|
if ($buffer === false) {
|
||||||
\uv_fs_close($this->loop, $fh, function () use ($deferred) {
|
\uv_fs_close($this->loop, $fh, function () use ($deferred) {
|
||||||
$this->driver->unreference($this->busy);
|
$this->driver->unreference($this->busy);
|
||||||
$deferred->fail(new FilesystemException(
|
$deferred->fail(new FilesystemException(
|
||||||
@ -571,7 +575,7 @@ class UvDriver implements Driver {
|
|||||||
$deferred = new Deferred;
|
$deferred = new Deferred;
|
||||||
$len = strlen($contents);
|
$len = strlen($contents);
|
||||||
\uv_fs_write($this->loop, $fh, $contents, $offset = 0, function ($fh, $result) use ($deferred, $len) {
|
\uv_fs_write($this->loop, $fh, $contents, $offset = 0, function ($fh, $result) use ($deferred, $len) {
|
||||||
\uv_fs_close($this->loop, $fh, function() use ($deferred, $result, $len) {
|
\uv_fs_close($this->loop, $fh, function () use ($deferred, $result, $len) {
|
||||||
$this->driver->unreference($this->busy);
|
$this->driver->unreference($this->busy);
|
||||||
if ($result < 0) {
|
if ($result < 0) {
|
||||||
$deferred->fail(new FilesystemException(
|
$deferred->fail(new FilesystemException(
|
||||||
|
@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
namespace Amp\File;
|
namespace Amp\File;
|
||||||
|
|
||||||
use Amp\{ Deferred, Loop, Promise, Success };
|
use Amp\Deferred;
|
||||||
|
use Amp\Loop;
|
||||||
|
use Amp\Promise;
|
||||||
|
use Amp\Success;
|
||||||
|
|
||||||
class UvHandle implements Handle {
|
class UvHandle implements Handle {
|
||||||
const OP_READ = 1;
|
const OP_READ = 1;
|
||||||
@ -205,7 +208,7 @@ class UvHandle implements Handle {
|
|||||||
$this->isCloseInitialized = true;
|
$this->isCloseInitialized = true;
|
||||||
$this->driver->reference($this->busy);
|
$this->driver->reference($this->busy);
|
||||||
$deferred = new Deferred;
|
$deferred = new Deferred;
|
||||||
\uv_fs_close($this->loop, $this->fh, function($fh) use ($deferred) {
|
\uv_fs_close($this->loop, $this->fh, function ($fh) use ($deferred) {
|
||||||
$this->driver->unreference($this->busy);
|
$this->driver->unreference($this->busy);
|
||||||
$deferred->resolve();
|
$deferred->resolve();
|
||||||
});
|
});
|
||||||
|
@ -2,13 +2,14 @@
|
|||||||
|
|
||||||
namespace Amp\File;
|
namespace Amp\File;
|
||||||
|
|
||||||
use Amp\{ Loop, Promise };
|
use Amp\Loop;
|
||||||
use Amp\Parallel\Worker\Worker;
|
use Amp\Parallel\Worker\Worker;
|
||||||
|
use Amp\Promise;
|
||||||
|
|
||||||
const LOOP_STATE_IDENTIFIER = Driver::class;
|
const LOOP_STATE_IDENTIFIER = Driver::class;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the application-wide filesystem instance
|
* Retrieve the application-wide filesystem instance.
|
||||||
*
|
*
|
||||||
* @param \Amp\File\Driver $driver Use the specified object as the application-wide filesystem instance
|
* @param \Amp\File\Driver $driver Use the specified object as the application-wide filesystem instance
|
||||||
* @return \Amp\File\Driver
|
* @return \Amp\File\Driver
|
||||||
@ -27,26 +28,26 @@ function filesystem(Driver $driver = null): Driver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new filesystem driver best-suited for the current environment
|
* Create a new filesystem driver best-suited for the current environment.
|
||||||
*
|
*
|
||||||
* @return \Amp\File\Driver
|
* @return \Amp\File\Driver
|
||||||
*/
|
*/
|
||||||
function driver(): Driver {
|
function driver(): Driver {
|
||||||
$driver = Loop::get();
|
$driver = Loop::get();
|
||||||
$loop = $driver->getHandle();
|
|
||||||
if (\is_resource($loop) && \get_resource_type($loop) == "uv_loop") {
|
if ($driver instanceof Loop\UvDriver) {
|
||||||
return new UvDriver($driver);
|
return new UvDriver($driver);
|
||||||
} elseif (\extension_loaded("eio")) {
|
|
||||||
return new EioDriver;
|
|
||||||
} elseif (\interface_exists(Worker::class)) {
|
|
||||||
return new ParallelDriver;
|
|
||||||
} else {
|
|
||||||
return new BlockingDriver;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (\extension_loaded("eio")) {
|
||||||
|
return new EioDriver;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ParallelDriver;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a handle for the specified path
|
* Open a handle for the specified path.
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param string $mode
|
* @param string $mode
|
||||||
@ -57,7 +58,7 @@ function open(string $path, string $mode): Promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute a file stat operation
|
* Execute a file stat operation.
|
||||||
*
|
*
|
||||||
* If the requested path does not exist the resulting Promise will resolve to NULL.
|
* If the requested path does not exist the resulting Promise will resolve to NULL.
|
||||||
* The returned Promise whould never resolve as a failure.
|
* The returned Promise whould never resolve as a failure.
|
||||||
@ -123,7 +124,7 @@ function isfile(string $path): Promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the path's last modification time as a unix timestamp
|
* Retrieve the path's last modification time as a unix timestamp.
|
||||||
*
|
*
|
||||||
* @param string $path An absolute file system path
|
* @param string $path An absolute file system path
|
||||||
* @fails \Amp\Files\FilesystemException If the path does not exist
|
* @fails \Amp\Files\FilesystemException If the path does not exist
|
||||||
@ -134,7 +135,7 @@ function mtime(string $path): Promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the path's last access time as a unix timestamp
|
* Retrieve the path's last access time as a unix timestamp.
|
||||||
*
|
*
|
||||||
* @param string $path An absolute file system path
|
* @param string $path An absolute file system path
|
||||||
* @fails \Amp\Files\FilesystemException If the path does not exist
|
* @fails \Amp\Files\FilesystemException If the path does not exist
|
||||||
@ -145,7 +146,7 @@ function atime($path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the path's creation time as a unix timestamp
|
* Retrieve the path's creation time as a unix timestamp.
|
||||||
*
|
*
|
||||||
* @param string $path An absolute file system path
|
* @param string $path An absolute file system path
|
||||||
* @fails \Amp\Files\FilesystemException If the path does not exist
|
* @fails \Amp\Files\FilesystemException If the path does not exist
|
||||||
@ -156,7 +157,7 @@ function ctime(string $path): Promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Same as stat() except if the path is a link then the link's data is returned
|
* Same as stat() except if the path is a link then the link's data is returned.
|
||||||
*
|
*
|
||||||
* If the requested path does not exist the resulting Promise will resolve to NULL.
|
* If the requested path does not exist the resulting Promise will resolve to NULL.
|
||||||
* The returned Promise whould never resolve as a failure.
|
* The returned Promise whould never resolve as a failure.
|
||||||
@ -169,7 +170,7 @@ function lstat(string $path): Promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a symlink $link pointing to the file/directory located at $original
|
* Create a symlink $link pointing to the file/directory located at $original.
|
||||||
*
|
*
|
||||||
* @param string $original
|
* @param string $original
|
||||||
* @param string $link
|
* @param string $link
|
||||||
@ -181,7 +182,7 @@ function symlink(string $original, string $link): Promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a hard link $link pointing to the file/directory located at $original
|
* Create a hard link $link pointing to the file/directory located at $original.
|
||||||
*
|
*
|
||||||
* @param string $original
|
* @param string $original
|
||||||
* @param string $link
|
* @param string $link
|
||||||
@ -193,7 +194,7 @@ function link(string $original, string $link): Promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read the symlink at $path
|
* Read the symlink at $path.
|
||||||
*
|
*
|
||||||
* @param string $original
|
* @param string $original
|
||||||
* @param string $link
|
* @param string $link
|
||||||
@ -205,7 +206,7 @@ function readlink(string $path): Promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rename a file or directory
|
* Rename a file or directory.
|
||||||
*
|
*
|
||||||
* @param string $from
|
* @param string $from
|
||||||
* @param string $to
|
* @param string $to
|
||||||
@ -217,7 +218,7 @@ function rename(string $from, string $to): Promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a file
|
* Delete a file.
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @return \Amp\Promise<null>
|
* @return \Amp\Promise<null>
|
||||||
@ -227,7 +228,7 @@ function unlink(string $path): Promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a director
|
* Create a director.
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param int $mode
|
* @param int $mode
|
||||||
@ -239,7 +240,7 @@ function mkdir(string $path, int $mode = 0644, bool $recursive = false): Promise
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a directory
|
* Delete a directory.
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @return \Amp\Promise<null>
|
* @return \Amp\Promise<null>
|
||||||
@ -249,7 +250,7 @@ function rmdir(string $path): Promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve an array of files and directories inside the specified path
|
* Retrieve an array of files and directories inside the specified path.
|
||||||
*
|
*
|
||||||
* Dot entries are not included in the resulting array (i.e. "." and "..").
|
* Dot entries are not included in the resulting array (i.e. "." and "..").
|
||||||
*
|
*
|
||||||
@ -261,7 +262,7 @@ function scandir(string $path): Promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* chmod a file or directory
|
* chmod a file or directory.
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param int $mode
|
* @param int $mode
|
||||||
@ -272,7 +273,7 @@ function chmod(string $path, int $mode): Promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* chown a file or directory
|
* chown a file or directory.
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param int $uid -1 to ignore
|
* @param int $uid -1 to ignore
|
||||||
@ -284,7 +285,7 @@ function chown(string $path, int $uid, int $gid = -1): Promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the access and modification time of the specified path
|
* Update the access and modification time of the specified path.
|
||||||
*
|
*
|
||||||
* If the file does not exist it will be created automatically.
|
* If the file does not exist it will be created automatically.
|
||||||
*
|
*
|
||||||
@ -296,7 +297,7 @@ function touch(string $path): Promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Buffer the specified file's contents
|
* Buffer the specified file's contents.
|
||||||
*
|
*
|
||||||
* @param string $path The file path from which to buffer contents
|
* @param string $path The file path from which to buffer contents
|
||||||
* @return \Amp\Promise<string>
|
* @return \Amp\Promise<string>
|
||||||
|
@ -4,7 +4,7 @@ namespace Amp\File\Test;
|
|||||||
|
|
||||||
class BlockingDriverTest extends DriverTest {
|
class BlockingDriverTest extends DriverTest {
|
||||||
protected function execute(callable $cb) {
|
protected function execute(callable $cb) {
|
||||||
\Amp\Loop::run(function() use ($cb) {
|
\Amp\Loop::run(function () use ($cb) {
|
||||||
\Amp\File\filesystem(new \Amp\File\BlockingDriver);
|
\Amp\File\filesystem(new \Amp\File\BlockingDriver);
|
||||||
\Amp\Promise\rethrow(new \Amp\Coroutine($cb()));
|
\Amp\Promise\rethrow(new \Amp\Coroutine($cb()));
|
||||||
});
|
});
|
||||||
|
@ -4,7 +4,7 @@ namespace Amp\File\Test;
|
|||||||
|
|
||||||
class BlockingHandleTest extends HandleTest {
|
class BlockingHandleTest extends HandleTest {
|
||||||
protected function execute(callable $cb) {
|
protected function execute(callable $cb) {
|
||||||
\Amp\Loop::run(function() use ($cb) {
|
\Amp\Loop::run(function () use ($cb) {
|
||||||
\Amp\File\filesystem(new \Amp\File\BlockingDriver);
|
\Amp\File\filesystem(new \Amp\File\BlockingDriver);
|
||||||
\Amp\Promise\rethrow(new \Amp\Coroutine($cb()));
|
\Amp\Promise\rethrow(new \Amp\Coroutine($cb()));
|
||||||
});
|
});
|
||||||
|
@ -64,7 +64,7 @@ abstract class DriverTest extends TestCase {
|
|||||||
$target = "{$fixtureDir}/small.txt";
|
$target = "{$fixtureDir}/small.txt";
|
||||||
$link = "{$fixtureDir}/symlink.txt";
|
$link = "{$fixtureDir}/symlink.txt";
|
||||||
$this->assertTrue(yield File\symlink($target, $link));
|
$this->assertTrue(yield File\symlink($target, $link));
|
||||||
$this->assertTrue(is_array(yield File\lstat($link)));
|
$this->assertInternalType('array', yield File\lstat($link));
|
||||||
yield File\unlink($link);
|
yield File\unlink($link);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ namespace Amp\File\Test;
|
|||||||
class EioDriverTest extends DriverTest {
|
class EioDriverTest extends DriverTest {
|
||||||
protected function execute(callable $cb) {
|
protected function execute(callable $cb) {
|
||||||
if (\extension_loaded("eio")) {
|
if (\extension_loaded("eio")) {
|
||||||
\Amp\Loop::run(function() use ($cb) {
|
\Amp\Loop::run(function () use ($cb) {
|
||||||
\Amp\File\filesystem(new \Amp\File\EioDriver);
|
\Amp\File\filesystem(new \Amp\File\EioDriver);
|
||||||
\Amp\Promise\rethrow(new \Amp\Coroutine($cb()));
|
\Amp\Promise\rethrow(new \Amp\Coroutine($cb()));
|
||||||
});
|
});
|
||||||
|
@ -7,7 +7,7 @@ use Amp\File as file;
|
|||||||
class EioHandleTest extends HandleTest {
|
class EioHandleTest extends HandleTest {
|
||||||
protected function execute(callable $cb) {
|
protected function execute(callable $cb) {
|
||||||
if (\extension_loaded("eio")) {
|
if (\extension_loaded("eio")) {
|
||||||
\Amp\Loop::run(function() use ($cb) {
|
\Amp\Loop::run(function () use ($cb) {
|
||||||
\Amp\File\filesystem(new \Amp\File\EioDriver);
|
\Amp\File\filesystem(new \Amp\File\EioDriver);
|
||||||
\Amp\Promise\rethrow(new \Amp\Coroutine($cb()));
|
\Amp\Promise\rethrow(new \Amp\Coroutine($cb()));
|
||||||
});
|
});
|
||||||
|
@ -9,7 +9,7 @@ use function Amp\call;
|
|||||||
|
|
||||||
class ParallelDriverTest extends DriverTest {
|
class ParallelDriverTest extends DriverTest {
|
||||||
protected function execute(callable $cb) {
|
protected function execute(callable $cb) {
|
||||||
Loop::run(function() use ($cb) {
|
Loop::run(function () use ($cb) {
|
||||||
$pool = new DefaultPool;
|
$pool = new DefaultPool;
|
||||||
$pool->start();
|
$pool->start();
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ use function Amp\call;
|
|||||||
|
|
||||||
class ParallelHandleTest extends HandleTest {
|
class ParallelHandleTest extends HandleTest {
|
||||||
protected function execute(callable $cb) {
|
protected function execute(callable $cb) {
|
||||||
Loop::run(function() use ($cb) {
|
Loop::run(function () use ($cb) {
|
||||||
$pool = new DefaultPool;
|
$pool = new DefaultPool;
|
||||||
$pool->start();
|
$pool->start();
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ class UvDriverTest extends DriverTest {
|
|||||||
if (\extension_loaded("uv")) {
|
if (\extension_loaded("uv")) {
|
||||||
$loop = new Loop\UvDriver;
|
$loop = new Loop\UvDriver;
|
||||||
Loop::set($loop);
|
Loop::set($loop);
|
||||||
Loop::run(function() use ($cb, $loop) {
|
Loop::run(function () use ($cb, $loop) {
|
||||||
\Amp\File\filesystem(new \Amp\File\UvDriver($loop));
|
\Amp\File\filesystem(new \Amp\File\UvDriver($loop));
|
||||||
\Amp\Promise\rethrow(new \Amp\Coroutine($cb()));
|
\Amp\Promise\rethrow(new \Amp\Coroutine($cb()));
|
||||||
});
|
});
|
||||||
|
@ -2,15 +2,15 @@
|
|||||||
|
|
||||||
namespace Amp\File\Test;
|
namespace Amp\File\Test;
|
||||||
|
|
||||||
use Amp\Loop;
|
|
||||||
use Amp\File as file;
|
use Amp\File as file;
|
||||||
|
use Amp\Loop;
|
||||||
|
|
||||||
class UvHandleTest extends HandleTest {
|
class UvHandleTest extends HandleTest {
|
||||||
protected function execute(callable $cb) {
|
protected function execute(callable $cb) {
|
||||||
if (\extension_loaded("uv")) {
|
if (\extension_loaded("uv")) {
|
||||||
$loop = new Loop\UvDriver;
|
$loop = new Loop\UvDriver;
|
||||||
Loop::set($loop);
|
Loop::set($loop);
|
||||||
Loop::run(function() use ($cb, $loop) {
|
Loop::run(function () use ($cb, $loop) {
|
||||||
\Amp\File\filesystem(new \Amp\File\UvDriver($loop));
|
\Amp\File\filesystem(new \Amp\File\UvDriver($loop));
|
||||||
\Amp\Promise\rethrow(new \Amp\Coroutine($cb()));
|
\Amp\Promise\rethrow(new \Amp\Coroutine($cb()));
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user