mirror of
https://github.com/danog/file.git
synced 2024-11-30 04:19:39 +01:00
renaming
This commit is contained in:
parent
dcfb210792
commit
07e110ac03
16
README.md
16
README.md
@ -1,12 +1,12 @@
|
||||
# fs
|
||||
# filesystem
|
||||
|
||||
[![Build Status](https://img.shields.io/travis/amphp/fs/master.svg?style=flat-square)](https://travis-ci.org/amphp/fs)
|
||||
[![CoverageStatus](https://img.shields.io/coveralls/amphp/fs/master.svg?style=flat-square)](https://coveralls.io/github/amphp/fs?branch=master)
|
||||
[![Build Status](https://img.shields.io/travis/amphp/filesystem/master.svg?style=flat-square)](https://travis-ci.org/amphp/filesystem)
|
||||
[![CoverageStatus](https://img.shields.io/coveralls/amphp/filesystem/master.svg?style=flat-square)](https://coveralls.io/github/amphp/filesystem?branch=master)
|
||||
![Unstable](https://img.shields.io/badge/api-unstable-orange.svg?style=flat-square)
|
||||
![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)
|
||||
|
||||
|
||||
`amphp/fs` is a non-blocking filesystem library for use with the [`amp`](https://github.com/amphp/amp)
|
||||
`amphp/filesystem` is a non-blocking filesystem library for use with the [`amp`](https://github.com/amphp/amp)
|
||||
concurrency framework.
|
||||
|
||||
**Dependencies**
|
||||
@ -15,19 +15,19 @@ concurrency framework.
|
||||
- [eio](https://pecl.php.net/package/eio)
|
||||
- [php-uv](https://github.com/bwoebi/php-uv) (experimental, requires PHP7)
|
||||
|
||||
`amphp/fs` works out of the box without any PHP extensions but it does so using
|
||||
`amphp/filesystem` works out of the box without any PHP extensions but it does so using
|
||||
blocking functions. This capability only exists to simplify development across
|
||||
environments where extensions may not be present. Using `amp/fs` in production
|
||||
environments where extensions may not be present. Using `amphp/filesystem` in production
|
||||
without pecl/eio or php-uv is **NOT** recommended.
|
||||
|
||||
**Current Version**
|
||||
|
||||
`amphp/fs` is currently pre-alpha software and has no tagged releases. Your mileage may vary.
|
||||
`amphp/filesystem` is currently pre-alpha software and has no tagged releases. Your mileage may vary.
|
||||
|
||||
**Installation**
|
||||
|
||||
```bash
|
||||
$ composer require amphp/fs:dev-master
|
||||
$ composer require amphp/filesystem:dev-master
|
||||
```
|
||||
|
||||
**TODO**
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "amphp/fs",
|
||||
"homepage": "https://github.com/amphp/fs",
|
||||
"name": "amphp/filesystem",
|
||||
"homepage": "https://github.com/amphp/filesystem",
|
||||
"description": "Non-blocking filesystem tools for amp applications",
|
||||
"keywords": [
|
||||
"filesystem",
|
||||
@ -14,8 +14,7 @@
|
||||
"authors": [
|
||||
{
|
||||
"name": "Daniel Lowrey",
|
||||
"email": "rdlowrey@php.net",
|
||||
"role": "Creator / Lead Developer"
|
||||
"email": "rdlowrey@php.net"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
@ -29,13 +28,13 @@
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Amp\\Fs\\": "lib"
|
||||
"Amp\\Filesystem\\": "lib"
|
||||
},
|
||||
"files": ["lib/functions.php"]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Amp\\Fs\\Test\\": "test/"
|
||||
"Amp\\Filesystem\\Test\\": "test/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
|
@ -1,12 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Amp\Fs;
|
||||
namespace Amp\Filesystem;
|
||||
|
||||
use Amp\Promise;
|
||||
use Amp\Success;
|
||||
use Amp\Failure;
|
||||
|
||||
class BlockingFilesystem implements Filesystem {
|
||||
class BlockingDriver implements Driver {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Amp\Fs;
|
||||
namespace Amp\Filesystem;
|
||||
|
||||
interface Filesystem {
|
||||
interface Driver {
|
||||
/**
|
||||
* Execute a file stat operation
|
||||
*
|
@ -1,13 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Amp\Fs;
|
||||
namespace Amp\Filesystem;
|
||||
|
||||
use Amp\Promise;
|
||||
use Amp\Success;
|
||||
use Amp\Failure;
|
||||
use Amp\Deferred;
|
||||
|
||||
class EioFilesystem implements Filesystem {
|
||||
class EioDriver implements Driver {
|
||||
private static $isEioInitialized = false;
|
||||
private $stream;
|
||||
private $watcher;
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Amp\Fs;
|
||||
namespace Amp\Filesystem;
|
||||
|
||||
use Amp\UvReactor;
|
||||
use Amp\Promise;
|
||||
@ -10,7 +10,7 @@ use Amp\Deferred;
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class UvFilesystem implements Filesystem {
|
||||
class UvDriver implements Driver {
|
||||
private $reactor;
|
||||
private $loop;
|
||||
|
@ -1,36 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Amp\Fs;
|
||||
namespace Amp\Filesystem;
|
||||
|
||||
/**
|
||||
* Retrieve the application-wide filesystem instance
|
||||
*
|
||||
* @param \Amp\Fs\Filesystem $assign Use the specified object as the application-wide filesystem instance
|
||||
* @return \Amp\Fs\Filesystem
|
||||
* @param \Amp\Fs\Driver $assign Use the specified object as the application-wide filesystem instance
|
||||
* @return \Amp\Fs\Driver
|
||||
*/
|
||||
function filesystem(Filesystem $assign = null) {
|
||||
static $filesystem;
|
||||
function filesystem(Driver $assign = null) {
|
||||
static $driver;
|
||||
if ($assign) {
|
||||
return ($filesystem = $assign);
|
||||
} elseif ($filesystem) {
|
||||
return $filesystem;
|
||||
return ($driver = $assign);
|
||||
} elseif ($driver) {
|
||||
return $driver;
|
||||
} else {
|
||||
return ($filesystem = init());
|
||||
return ($driver = driver());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new filesystem instance best-suited for the current environment
|
||||
* Create a new filesystem driver best-suited for the current environment
|
||||
*
|
||||
* @return \Amp\Fs\Filesystem
|
||||
*/
|
||||
function init() {
|
||||
if (\extension_loaded("uv")) {
|
||||
return new UvFilesystem(\Amp\reactor());
|
||||
function driver() {
|
||||
$reactor = \Amp\reactor();
|
||||
if ($reactor instanceof \Amp\UvReactor) {
|
||||
return new UvDriver($reactor);
|
||||
} elseif (\extension_loaded("eio")) {
|
||||
return new EioFilesystem;
|
||||
return new EioDriver;
|
||||
} else {
|
||||
return BlockingFilesystem;
|
||||
return BlockingDriver;
|
||||
}
|
||||
}
|
||||
|
||||
|
10
test/BlockingDriverTest.php
Normal file
10
test/BlockingDriverTest.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Amp\Filesystem\Test;
|
||||
|
||||
class BlockingDriverTest extends DriverTest {
|
||||
protected function setUp() {
|
||||
\Amp\reactor(\Amp\init());
|
||||
\Amp\Filesystem\filesystem(new \Amp\Filesystem\BlockingDriver);
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Amp\Fs\Test;
|
||||
|
||||
class BlockingFilesystemTest extends FilesystemTest {
|
||||
protected function setUp() {
|
||||
\Amp\reactor(\Amp\init());
|
||||
\Amp\Fs\filesystem(new \Amp\Fs\BlockingFilesystem);
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Amp\Fs\Test;
|
||||
namespace Amp\Filesystem\Test;
|
||||
|
||||
use Amp\Fs\Filesystem;
|
||||
use Amp\Filesystem\Driver;
|
||||
|
||||
abstract class FilesystemTest extends \PHPUnit_Framework_TestCase {
|
||||
abstract class DriverTest extends \PHPUnit_Framework_TestCase {
|
||||
private static $fixtureId;
|
||||
|
||||
private static function getFixturePath() {
|
||||
@ -21,10 +21,10 @@ abstract class FilesystemTest extends \PHPUnit_Framework_TestCase {
|
||||
return;
|
||||
}
|
||||
|
||||
if (stripos(\PHP_OS, "win") === 0) {
|
||||
system('rd /Q /S "' . $fixtureDir . '"');
|
||||
if (\stripos(\PHP_OS, "win") === 0) {
|
||||
\system('rd /Q /S "' . $fixtureDir . '"');
|
||||
} else {
|
||||
system('/bin/rm -rf ' . escapeshellarg($fixtureDir));
|
||||
\system('/bin/rm -rf ' . escapeshellarg($fixtureDir));
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,17 +33,17 @@ abstract class FilesystemTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
self::clearFixtureDir();
|
||||
|
||||
if (!mkdir($fixtureDir, $mode = 0777, $recursive = true)) {
|
||||
if (!\mkdir($fixtureDir, $mode = 0777, $recursive = true)) {
|
||||
throw new \RuntimeException(
|
||||
"Failed creating temporary test fixture directory: {$fixtureDir}"
|
||||
);
|
||||
}
|
||||
if (!mkdir($fixtureDir . "/dir", $mode = 0777, $recursive = true)) {
|
||||
if (!\mkdir($fixtureDir . "/dir", $mode = 0777, $recursive = true)) {
|
||||
throw new \RuntimeException(
|
||||
"Failed creating temporary test fixture directory"
|
||||
);
|
||||
}
|
||||
if (!file_put_contents($fixtureDir . "/small.txt", "small")) {
|
||||
if (!\file_put_contents($fixtureDir . "/small.txt", "small")) {
|
||||
throw new \RuntimeException(
|
||||
"Failed creating temporary test fixture file"
|
||||
);
|
||||
@ -57,7 +57,7 @@ abstract class FilesystemTest extends \PHPUnit_Framework_TestCase {
|
||||
public function testScandir() {
|
||||
\Amp\run(function () {
|
||||
$fixtureDir = self::getFixturePath();
|
||||
$actual = (yield \Amp\Fs\scandir($fixtureDir));
|
||||
$actual = (yield \Amp\Filesystem\scandir($fixtureDir));
|
||||
$expected = ["dir", "small.txt"];
|
||||
$this->assertSame($expected, $actual);
|
||||
});
|
||||
@ -69,9 +69,9 @@ abstract class FilesystemTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
$target = "{$fixtureDir}/small.txt";
|
||||
$link = "{$fixtureDir}/symlink.txt";
|
||||
$this->assertTrue(yield \Amp\Fs\symlink($target, $link));
|
||||
$this->assertTrue(yield \Amp\Filesystem\symlink($target, $link));
|
||||
$this->assertTrue(\is_link($link));
|
||||
yield \Amp\Fs\unlink($link);
|
||||
yield \Amp\Filesystem\unlink($link);
|
||||
});
|
||||
}
|
||||
|
||||
@ -81,9 +81,9 @@ abstract class FilesystemTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
$target = "{$fixtureDir}/small.txt";
|
||||
$link = "{$fixtureDir}/symlink.txt";
|
||||
$this->assertTrue(yield \Amp\Fs\symlink($target, $link));
|
||||
$this->assertTrue(is_array(yield \Amp\Fs\lstat($link)));
|
||||
yield \Amp\Fs\unlink($link);
|
||||
$this->assertTrue(yield \Amp\Filesystem\symlink($target, $link));
|
||||
$this->assertTrue(is_array(yield \Amp\Filesystem\lstat($link)));
|
||||
yield \Amp\Filesystem\unlink($link);
|
||||
});
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ abstract class FilesystemTest extends \PHPUnit_Framework_TestCase {
|
||||
\Amp\run(function () {
|
||||
$fixtureDir = self::getFixturePath();
|
||||
|
||||
$stat = (yield \Amp\Fs\stat("{$fixtureDir}/small.txt"));
|
||||
$stat = (yield \Amp\Filesystem\stat("{$fixtureDir}/small.txt"));
|
||||
$this->assertInternalType("array", $stat);
|
||||
$this->assertTrue($stat["isfile"]);
|
||||
$this->assertFalse($stat["isdir"]);
|
||||
@ -102,7 +102,7 @@ abstract class FilesystemTest extends \PHPUnit_Framework_TestCase {
|
||||
\Amp\run(function () {
|
||||
$fixtureDir = self::getFixturePath();
|
||||
|
||||
$stat = (yield \Amp\Fs\stat("{$fixtureDir}/dir"));
|
||||
$stat = (yield \Amp\Filesystem\stat("{$fixtureDir}/dir"));
|
||||
$this->assertInternalType("array", $stat);
|
||||
$this->assertTrue($stat["isdir"]);
|
||||
$this->assertFalse($stat["isfile"]);
|
||||
@ -113,7 +113,7 @@ abstract class FilesystemTest extends \PHPUnit_Framework_TestCase {
|
||||
\Amp\run(function () {
|
||||
$fixtureDir = self::getFixturePath();
|
||||
|
||||
$stat = (yield \Amp\Fs\stat("{$fixtureDir}/nonexistent"));
|
||||
$stat = (yield \Amp\Filesystem\stat("{$fixtureDir}/nonexistent"));
|
||||
$this->assertNull($stat);
|
||||
});
|
||||
}
|
||||
@ -126,10 +126,10 @@ abstract class FilesystemTest extends \PHPUnit_Framework_TestCase {
|
||||
$old = "{$fixtureDir}/rename1.txt";
|
||||
$new = "{$fixtureDir}/rename2.txt";
|
||||
|
||||
yield \Amp\Fs\put($old, $contents1);
|
||||
yield \Amp\Fs\rename($old, $new);
|
||||
$contents2 = (yield \Amp\Fs\get($new));
|
||||
yield \Amp\Fs\unlink($new);
|
||||
yield \Amp\Filesystem\put($old, $contents1);
|
||||
yield \Amp\Filesystem\rename($old, $new);
|
||||
$contents2 = (yield \Amp\Filesystem\get($new));
|
||||
yield \Amp\Filesystem\unlink($new);
|
||||
|
||||
$this->assertSame($contents1, $contents2);
|
||||
});
|
||||
@ -141,10 +141,10 @@ abstract class FilesystemTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
$toUnlink = "{$fixtureDir}/unlink";
|
||||
|
||||
yield \Amp\Fs\put($toUnlink, "unlink me");
|
||||
$this->assertTrue((bool) (yield \Amp\Fs\stat($toUnlink)));
|
||||
yield \Amp\Fs\unlink($toUnlink);
|
||||
$this->assertNull(yield \Amp\Fs\stat($toUnlink));
|
||||
yield \Amp\Filesystem\put($toUnlink, "unlink me");
|
||||
$this->assertTrue((bool) (yield \Amp\Filesystem\stat($toUnlink)));
|
||||
yield \Amp\Filesystem\unlink($toUnlink);
|
||||
$this->assertNull(yield \Amp\Filesystem\stat($toUnlink));
|
||||
});
|
||||
}
|
||||
|
||||
@ -154,12 +154,12 @@ abstract class FilesystemTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
$dir = "{$fixtureDir}/newdir";
|
||||
|
||||
yield \Amp\Fs\mkdir($dir);
|
||||
$stat = (yield \Amp\Fs\stat($dir));
|
||||
yield \Amp\Filesystem\mkdir($dir);
|
||||
$stat = (yield \Amp\Filesystem\stat($dir));
|
||||
$this->assertTrue($stat["isdir"]);
|
||||
$this->assertFalse($stat["isfile"]);
|
||||
yield \Amp\Fs\rmdir($dir);
|
||||
$this->assertNull(yield \Amp\Fs\stat($dir));
|
||||
yield \Amp\Filesystem\rmdir($dir);
|
||||
$this->assertNull(yield \Amp\Filesystem\stat($dir));
|
||||
});
|
||||
}
|
||||
|
||||
@ -171,13 +171,13 @@ abstract class FilesystemTest extends \PHPUnit_Framework_TestCase {
|
||||
$fixtureDir = self::getFixturePath();
|
||||
|
||||
$touch = "{$fixtureDir}/touch";
|
||||
yield \Amp\Fs\put($touch, "touch me");
|
||||
yield \Amp\Filesystem\put($touch, "touch me");
|
||||
|
||||
$oldStat = (yield \Amp\Fs\stat($touch));
|
||||
$oldStat = (yield \Amp\Filesystem\stat($touch));
|
||||
sleep(1);
|
||||
yield \Amp\Fs\touch($touch);
|
||||
$newStat = (yield \Amp\Fs\stat($touch));
|
||||
yield \Amp\Fs\unlink($touch);
|
||||
yield \Amp\Filesystem\touch($touch);
|
||||
$newStat = (yield \Amp\Filesystem\stat($touch));
|
||||
yield \Amp\Filesystem\unlink($touch);
|
||||
|
||||
$this->assertTrue($newStat["atime"] > $oldStat["atime"]);
|
||||
$this->assertTrue($newStat["mtime"] > $oldStat["mtime"]);
|
@ -1,12 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Amp\Fs\Test;
|
||||
namespace Amp\Filesystem\Test;
|
||||
|
||||
class EioFilesystemTest extends FilesystemTest {
|
||||
class EioDriverTest extends DriverTest {
|
||||
protected function setUp() {
|
||||
if (extension_loaded("eio")) {
|
||||
\Amp\reactor(\Amp\init());
|
||||
\Amp\Fs\filesystem(new \Amp\Fs\EioFilesystem);
|
||||
\Amp\Filesystem\filesystem(new \Amp\Filesystem\EioDriver);
|
||||
} else {
|
||||
$this->markTestSkipped(
|
||||
"eio extension not loaded"
|
@ -1,13 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Amp\Fs\Test;
|
||||
namespace Amp\Filesystem\Test;
|
||||
|
||||
class UvFilesystemTest extends FilesystemTest {
|
||||
class UvDriverTest extends DriverTest {
|
||||
protected function setUp() {
|
||||
if (\extension_loaded("uv")) {
|
||||
$reactor = new \Amp\UvReactor;
|
||||
\Amp\reactor($reactor);
|
||||
\Amp\Fs\filesystem(new \Amp\Fs\UvFilesystem($reactor));
|
||||
$driver = new \Amp\Filesystem\UvDriver($reactor);
|
||||
\Amp\Filesystem\filesystem($driver);
|
||||
} else {
|
||||
$this->markTestSkipped(
|
||||
"php-uv extension not loaded"
|
Loading…
Reference in New Issue
Block a user