mirror of
https://github.com/danog/file.git
synced 2024-11-30 04:19:39 +01:00
Fixes EioDriver and UvDriver readlink implementation
This commit is contained in:
parent
3e5da2b245
commit
fa9534a038
@ -296,10 +296,19 @@ class EioDriver implements Driver {
|
|||||||
$this->poll->listen($deferred->promise());
|
$this->poll->listen($deferred->promise());
|
||||||
|
|
||||||
$priority = \EIO_PRI_DEFAULT;
|
$priority = \EIO_PRI_DEFAULT;
|
||||||
\eio_readlink($path, $priority, [$this, "onGenericResult"], $deferred);
|
\eio_readlink($path, $priority, [$this, "onReadlink"], $deferred);
|
||||||
|
|
||||||
return $deferred->promise();
|
return $deferred->promise();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function onReadlink($deferred, $result, $req) {
|
||||||
|
if ($result === -1) {
|
||||||
|
$deferred->fail(new FilesystemException(\eio_get_last_error($req)));
|
||||||
|
} else {
|
||||||
|
$deferred->resolve($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function onGenericResult($deferred, $result, $req) {
|
private function onGenericResult($deferred, $result, $req) {
|
||||||
if ($result === -1) {
|
if ($result === -1) {
|
||||||
$deferred->fail(new FilesystemException(\eio_get_last_error($req)));
|
$deferred->fail(new FilesystemException(\eio_get_last_error($req)));
|
||||||
|
@ -320,8 +320,12 @@ class UvDriver implements Driver {
|
|||||||
$deferred = new Deferred;
|
$deferred = new Deferred;
|
||||||
$this->poll->listen($deferred->promise());
|
$this->poll->listen($deferred->promise());
|
||||||
|
|
||||||
\uv_fs_readlink($this->loop, $path, function ($fh) use ($deferred) {
|
\uv_fs_readlink($this->loop, $path, function ($fh, $target) use ($deferred) {
|
||||||
$deferred->resolve((bool) $fh);
|
if (!(bool) $fh) {
|
||||||
|
$deferred->fail(new FilesystemException("Could not read symbolic link"));
|
||||||
|
}
|
||||||
|
|
||||||
|
$deferred->resolve($target);
|
||||||
});
|
});
|
||||||
|
|
||||||
return $deferred->promise();
|
return $deferred->promise();
|
||||||
|
@ -57,6 +57,43 @@ abstract class DriverTest extends TestCase {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testReadlink() {
|
||||||
|
$this->execute(function () {
|
||||||
|
$fixtureDir = Fixture::path();
|
||||||
|
|
||||||
|
$original = "{$fixtureDir}/small.txt";
|
||||||
|
$link = "{$fixtureDir}/symlink.txt";
|
||||||
|
\symlink($original, $link);
|
||||||
|
|
||||||
|
$this->assertSame($original, yield File\readlink($link));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function readlinkPathProvider() {
|
||||||
|
return [
|
||||||
|
'nonExistingPath' => [function () {
|
||||||
|
return Fixture::path() . '/' . uniqid();
|
||||||
|
}],
|
||||||
|
'notLink' => [function () {
|
||||||
|
return Fixture::path();
|
||||||
|
}],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider readlinkPathProvider
|
||||||
|
* @expectedException \Amp\File\FilesystemException
|
||||||
|
*
|
||||||
|
* @param \Closure $linkResolver
|
||||||
|
*/
|
||||||
|
public function testReadlinkError(\Closure $linkResolver) {
|
||||||
|
$this->execute(function () use ($linkResolver) {
|
||||||
|
$link = $linkResolver();
|
||||||
|
|
||||||
|
yield File\readlink($link);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function testLstat() {
|
public function testLstat() {
|
||||||
$this->execute(function () {
|
$this->execute(function () {
|
||||||
$fixtureDir = Fixture::path();
|
$fixtureDir = Fixture::path();
|
||||||
|
@ -22,4 +22,13 @@ class UvDriverTest extends DriverTest {
|
|||||||
asyncCall($cb);
|
asyncCall($cb);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider readlinkPathProvider
|
||||||
|
*
|
||||||
|
* @param \Closure $linkResolver
|
||||||
|
*/
|
||||||
|
public function testReadlinkError(\Closure $linkResolver) {
|
||||||
|
$this->markTestSkipped('UvDriver Test Skipped: Causes Crash');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user