@@ -314,27 +314,20 @@ public function fopen($path, $mode) {
314314 switch ($ mode ) {
315315 case 'r ' :
316316 case 'rb ' :
317- $ tmpFile = \OCP \Files::tmpFile ();
318- self ::$ tmpFiles [$ tmpFile ] = $ path ;
319- try {
320- $ object = $ this ->getContainer ()->getObject ($ path );
321- } catch (ClientErrorResponseException $ e ) {
322- \OCP \Util::writeLog ('files_external ' , $ e ->getMessage (), \OCP \Util::ERROR );
323- return false ;
324- } catch (Exception \ObjectNotFoundException $ e ) {
325- \OCP \Util::writeLog ('files_external ' , $ e ->getMessage (), \OCP \Util::ERROR );
326- return false ;
327- }
328317 try {
329- $ objectContent = $ object ->getContent ();
330- $ objectContent ->rewind ();
331- $ stream = $ objectContent ->getStream ();
332- file_put_contents ($ tmpFile , $ stream );
333- } catch (Exceptions \IOError $ e ) {
318+ $ c = $ this ->getContainer ();
319+ $ streamFactory = new \Guzzle \Stream \PhpStreamRequestFactory ();
320+ $ streamInterface = $ streamFactory ->fromRequest (
321+ $ c ->getClient ()
322+ ->get ($ c ->getUrl ($ path )));
323+ $ streamInterface ->rewind ();
324+ $ stream = $ streamInterface ->getStream ();
325+ stream_context_set_option ($ stream , 'swift ' ,'content ' , $ streamInterface );
326+ return $ stream ;
327+ } catch (\Guzzle \Http \Exception \BadResponseException $ e ) {
334328 \OCP \Util::writeLog ('files_external ' , $ e ->getMessage (), \OCP \Util::ERROR );
335329 return false ;
336330 }
337- return fopen ($ tmpFile , 'r ' );
338331 case 'w ' :
339332 case 'wb ' :
340333 case 'a ' :
0 commit comments