Exemple #1
0
 public function stat($cb, $pri = EIO_PRI_DEFAULT)
 {
     if (!FS::$supported) {
         call_user_func($cb, $this, FS::statPrepare(fstat($this->fd)));
         return;
     }
     if ($this->stat) {
         call_user_func($cb, $this, $this->stat);
     } else {
         eio_fstat($this->fd, $pri, function ($file, $stat) use($cb) {
             $stat = FS::statPrepare($stat);
             $file->stat = $stat;
             call_user_func($cb, $file, $stat);
         }, $this);
     }
 }
Exemple #2
0
 private function onGetOpen($promisor, $result, $req)
 {
     if ($result === -1) {
         $promisor->fail(new \RuntimeException(\eio_get_last_error($req)));
     } else {
         $priority = \EIO_PRI_DEFAULT;
         \eio_fstat($result, $priority, [$this, "onGetFstat"], [$result, $promisor]);
     }
 }
Exemple #3
0
 /**
  * Stat() non-cached
  * @param  callable $cb Callback
  * @param  integer $pri Priority
  * @return resource|boolean
  */
 public function statRefresh($cb, $pri = EIO_PRI_DEFAULT)
 {
     $cb = CallbackWrapper::forceWrap($cb);
     if (!$this->fd || $this->fd === -1) {
         if ($cb) {
             $cb($this, false);
         }
         return false;
     }
     if (!FileSystem::$supported) {
         $cb($this, FileSystem::statPrepare(fstat($this->fd)));
         return true;
     }
     return eio_fstat($this->fd, $pri, function ($file, $stat) use($cb) {
         $stat = FileSystem::statPrepare($stat);
         $file->stat = $stat;
         $cb($file, $stat);
     }, $this);
 }
Exemple #4
0
 /**
  * {@inheritdoc}
  */
 public function open(string $path, string $mode) : \Generator
 {
     $flags = $this->makeFlags($mode);
     $chmod = $flags & \EIO_O_CREAT ? 0644 : 0;
     $delayed = new Delayed();
     \eio_open($path, $flags, $chmod, 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();
     }
     if ($flags & \EIO_O_TRUNC) {
         // File truncated.
         $size = 0;
     } else {
         $delayed = new Delayed();
         \eio_fstat($handle, null, function (Delayed $delayed, $result, $req) {
             if (-1 === $result) {
                 $delayed->reject(new FileException(sprintf('Finding file size failed: %s.', \eio_get_last_error($req))));
             } else {
                 $delayed->resolve($result['size']);
             }
         }, $delayed);
         $this->poll->listen();
         try {
             $size = (yield $delayed);
         } finally {
             $this->poll->done();
         }
     }
     return new EioFile($this->poll, $handle, $path, $size, (bool) ($flags & \EIO_O_APPEND));
 }
Exemple #5
0
 /**
  * {@inheritdoc}
  */
 public function stat() : \Generator
 {
     if (!$this->isOpen()) {
         throw new FileException('The file has been closed.');
     }
     $delayed = new Delayed();
     \eio_fstat($this->handle, null, function (Delayed $delayed, $result, $req) {
         if (-1 === $result) {
             $delayed->reject(new FileException(sprintf('Getting file status failed: %s.', \eio_get_last_error($req))));
         } else {
             $delayed->resolve($result);
         }
     }, $delayed);
     $this->poll->listen();
     try {
         $stat = (yield $delayed);
     } finally {
         $this->poll->done();
     }
     $numeric = [];
     foreach (EioDriver::getStatKeys() as $key => $name) {
         $numeric[$key] = $stat[$name];
     }
     return array_merge($numeric, $stat);
 }