/** * {@inheritdoc} */ public function fopen($path, $mode) { try { $absPath = $this->absPath($path); switch ($mode) { case 'r': case 'rb': if (!$this->file_exists($path)) { return false; } case 'w': case 'wb': case 'a': case 'ab': case 'r+': case 'w+': case 'wb+': case 'a+': case 'x': case 'x+': case 'c': case 'c+': $context = stream_context_create(array('sftp' => array('session' => $this->getConnection()))); $handle = fopen($this->constructUrl($path), $mode, false, $context); return RetryWrapper::wrap($handle); } } catch (\Exception $e) { } return false; }
public function fopen($path, $mode) { $path = $this->root . $path; switch ($mode) { case 'r': case 'rb': try { // slashes need to stay $encodedPath = str_replace('%2F', '/', rawurlencode(trim($path, '/'))); $downloadUrl = 'https://api-content.dropbox.com/1/files/auto/' . $encodedPath; $headers = $this->oauth->getOAuthHeader($downloadUrl, [], 'GET'); $client = \OC::$server->getHTTPClientService()->newClient(); try { $response = $client->get($downloadUrl, ['headers' => $headers, 'stream' => true]); } catch (RequestException $e) { if (!is_null($e->getResponse())) { if ($e->getResponse()->getStatusCode() === 404) { return false; } else { throw $e; } } else { throw $e; } } $handle = $response->getBody(); return RetryWrapper::wrap($handle); } catch (\Exception $exception) { \OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR); return false; } case 'w': case 'wb': case 'a': case 'ab': case 'r+': case 'w+': case 'wb+': case 'a+': case 'x': case 'x+': case 'c': case 'c+': if (strrpos($path, '.') !== false) { $ext = substr($path, strrpos($path, '.')); } else { $ext = ''; } $tmpFile = \OCP\Files::tmpFile($ext); \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack')); if ($this->file_exists($path)) { $source = $this->fopen($path, 'r'); file_put_contents($tmpFile, $source); } self::$tempFiles[$tmpFile] = $path; return fopen('close://' . $tmpFile, $mode); } return false; }
public function fopen($path, $mode) { $pos = strrpos($path, '.'); if ($pos !== false) { $ext = substr($path, $pos); } else { $ext = ''; } switch ($mode) { case 'r': case 'rb': $file = $this->getDriveFile($path); if ($file) { $exportLinks = $file->getExportLinks(); $mimetype = $this->getMimeType($path); $downloadUrl = null; if ($exportLinks && isset($exportLinks[$mimetype])) { $downloadUrl = $exportLinks[$mimetype]; } else { $downloadUrl = $file->getDownloadUrl(); } if (isset($downloadUrl)) { $request = new \Google_Http_Request($downloadUrl, 'GET', null, null); $httpRequest = $this->client->getAuth()->sign($request); // the library's service doesn't support streaming, so we use Guzzle instead $client = \OC::$server->getHTTPClientService()->newClient(); try { $response = $client->get($downloadUrl, ['headers' => $httpRequest->getRequestHeaders(), 'stream' => true, 'verify' => realpath(__DIR__ . '/../../../3rdparty/google-api-php-client/src/Google/IO/cacerts.pem')]); } catch (RequestException $e) { if (!is_null($e->getResponse())) { if ($e->getResponse()->getStatusCode() === 404) { return false; } else { throw $e; } } else { throw $e; } } $handle = $response->getBody(); return RetryWrapper::wrap($handle); } } return false; case 'w': case 'wb': case 'a': case 'ab': case 'r+': case 'w+': case 'wb+': case 'a+': case 'x': case 'x+': case 'c': case 'c+': $tmpFile = \OCP\Files::tmpFile($ext); \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack')); if ($this->file_exists($path)) { $source = $this->fopen($path, 'rb'); file_put_contents($tmpFile, $source); } self::$tempFiles[$tmpFile] = $path; return fopen('close://' . $tmpFile, $mode); } }
public function fopen($path, $mode) { switch ($mode) { case 'r': case 'rb': case 'w': case 'wb': case 'a': case 'ab': //these are supported by the wrapper $context = stream_context_create(array('ftp' => array('overwrite' => true))); $handle = fopen($this->constructUrl($path), $mode, false, $context); return RetryWrapper::wrap($handle); 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 = ''; } $tmpFile = \OCP\Files::tmpFile($ext); \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack')); if ($this->file_exists($path)) { $this->getFile($path, $tmpFile); } self::$tempFiles[$tmpFile] = $path; return fopen('close://' . $tmpFile, $mode); } return false; }