Esempio n. 1
0
 /**
  * @param string $path
  * @param string $mode
  * @return resource
  */
 public function fopen($path, $mode)
 {
     $fullPath = $this->buildPath($path);
     try {
         switch ($mode) {
             case 'r':
             case 'rb':
                 if (!$this->file_exists($path)) {
                     return false;
                 }
                 return $this->share->read($fullPath);
             case 'w':
             case 'wb':
                 $source = $this->share->write($fullPath);
                 return CallBackWrapper::wrap($source, null, null, function () use($fullPath) {
                     unset($this->statCache[$fullPath]);
                 });
             case 'a':
             case 'ab':
             case 'r+':
             case 'w+':
             case 'wb+':
             case 'a+':
             case 'x':
             case 'x+':
             case 'c':
             case 'c+':
                 //emulate these
                 if (strrpos($path, '.') !== false) {
                     $ext = substr($path, strrpos($path, '.'));
                 } else {
                     $ext = '';
                 }
                 if ($this->file_exists($path)) {
                     if (!$this->isUpdatable($path)) {
                         return false;
                     }
                     $tmpFile = $this->getCachedFile($path);
                 } else {
                     if (!$this->isCreatable(dirname($path))) {
                         return false;
                     }
                     $tmpFile = \OCP\Files::tmpFile($ext);
                 }
                 $source = fopen($tmpFile, $mode);
                 $share = $this->share;
                 return CallbackWrapper::wrap($source, null, null, function () use($tmpFile, $fullPath, $share) {
                     unset($this->statCache[$fullPath]);
                     $share->put($tmpFile, $fullPath);
                     unlink($tmpFile);
                 });
         }
         return false;
     } catch (NotFoundException $e) {
         return false;
     } catch (ForbiddenException $e) {
         return false;
     }
 }