mirror of
https://github.com/danog/file.git
synced 2024-11-26 11:54:54 +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());
|
||||
|
||||
$priority = \EIO_PRI_DEFAULT;
|
||||
\eio_readlink($path, $priority, [$this, "onGenericResult"], $deferred);
|
||||
\eio_readlink($path, $priority, [$this, "onReadlink"], $deferred);
|
||||
|
||||
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) {
|
||||
if ($result === -1) {
|
||||
$deferred->fail(new FilesystemException(\eio_get_last_error($req)));
|
||||
|
@ -320,8 +320,12 @@ class UvDriver implements Driver {
|
||||
$deferred = new Deferred;
|
||||
$this->poll->listen($deferred->promise());
|
||||
|
||||
\uv_fs_readlink($this->loop, $path, function ($fh) use ($deferred) {
|
||||
$deferred->resolve((bool) $fh);
|
||||
\uv_fs_readlink($this->loop, $path, function ($fh, $target) use ($deferred) {
|
||||
if (!(bool) $fh) {
|
||||
$deferred->fail(new FilesystemException("Could not read symbolic link"));
|
||||
}
|
||||
|
||||
$deferred->resolve($target);
|
||||
});
|
||||
|
||||
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() {
|
||||
$this->execute(function () {
|
||||
$fixtureDir = Fixture::path();
|
||||
|
@ -22,4 +22,13 @@ class UvDriverTest extends DriverTest {
|
||||
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