@@ -323,27 +323,24 @@ public function fopen($path, $mode) {
323323 switch ($ mode ) {
324324 case 'r ' :
325325 case 'rb ' :
326- $ tmpFile = \OCP \Files::tmpFile ();
327- self ::$ tmpFiles [$ tmpFile ] = $ path ;
328326 try {
329- $ object = $ this ->getContainer ()->getObject ($ path );
330- } catch (ClientErrorResponseException $ e ) {
331- \OCP \Util::writeLog ('files_external ' , $ e ->getMessage (), \OCP \Util::ERROR );
332- return false ;
333- } catch (Exception \ObjectNotFoundException $ e ) {
334- \OCP \Util::writeLog ('files_external ' , $ e ->getMessage (), \OCP \Util::ERROR );
327+ $ c = $ this ->getContainer ();
328+ $ streamFactory = new \Guzzle \Stream \PhpStreamRequestFactory ();
329+ $ streamInterface = $ streamFactory ->fromRequest (
330+ $ c ->getClient ()
331+ ->get ($ c ->getUrl ($ path )));
332+ $ streamInterface ->rewind ();
333+ $ stream = $ streamInterface ->getStream ();
334+ stream_context_set_option ($ stream , 'swift ' ,'content ' , $ streamInterface );
335+ if (!strrpos ($ streamInterface
336+ ->getMetaData ('wrapper_data ' )[0 ], '404 Not Found ' )) {
337+ return $ stream ;
338+ }
335339 return false ;
336- }
337- try {
338- $ objectContent = $ object ->getContent ();
339- $ objectContent ->rewind ();
340- $ stream = $ objectContent ->getStream ();
341- file_put_contents ($ tmpFile , $ stream );
342- } catch (Exceptions \IOError $ e ) {
340+ } catch (\Guzzle \Http \Exception \BadResponseException $ e ) {
343341 \OCP \Util::writeLog ('files_external ' , $ e ->getMessage (), \OCP \Util::ERROR );
344342 return false ;
345343 }
346- return fopen ($ tmpFile , 'r ' );
347344 case 'w ' :
348345 case 'wb ' :
349346 case 'a ' :
0 commit comments