Exemplo n.º 1
0
 /**
  * @coroutine
  *
  * @param string $path
  *
  * @return \Generator
  *
  * @resolve int
  */
 public function copy(string $path) : \Generator
 {
     $delayed = new Delayed();
     \eio_open($path, \EIO_O_WRONLY | \EIO_O_CREAT | \EIO_O_TRUNC, 0644, null, function (Delayed $delayed, $handle, $req) {
         if (-1 === $handle) {
             $delayed->reject(new FileException(sprintf('Opening the file failed: %s.', \eio_get_last_error($req))));
         } else {
             $delayed->resolve($handle);
         }
     }, $delayed);
     $this->poll->listen();
     try {
         $handle = (yield $delayed);
     } finally {
         $this->poll->done();
     }
     $delayed = new Delayed();
     \eio_sendfile($handle, $this->handle, 0, $this->size, null, function (Delayed $delayed, $result, $req) {
         if (-1 === $result) {
             $delayed->reject(new FileException(sprintf('Copying the file failed: %s.', \eio_get_last_error($req))));
         } else {
             $delayed->resolve(true);
         }
     }, $delayed);
     $this->poll->listen();
     try {
         (yield $delayed);
     } finally {
         $this->poll->done();
         \eio_close($handle);
     }
     return $this->size;
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function chmod(string $path, int $mode) : \Generator
 {
     $delayed = new Delayed();
     \eio_chmod($path, $mode, null, function (Delayed $delayed, $result, $req) {
         if (-1 === $result) {
             $delayed->reject(new FileException(sprintf('Changing the owner failed: %s.', \eio_get_last_error($req))));
         } else {
             $delayed->resolve(true);
         }
     }, $delayed);
     $this->poll->listen();
     try {
         $result = (yield $delayed);
     } finally {
         $this->poll->done();
     }
     return $result;
 }