Esempio n. 1
0
 /**
  * @see FileBackendStore::getLocalCopy()
  */
 public function getLocalCopy(array $params)
 {
     list($srcCont, $srcRel) = $this->resolveStoragePathReal($params['src']);
     if ($srcRel === null) {
         return null;
     }
     /*if ( !$this->fileExists( $params ) ) {
     			return null;
     		}*/
     $tmpFile = null;
     try {
         $sContObj = $this->getContainer($srcCont);
         $obj = new CF_Object($sContObj, $srcRel, false, false);
         // skip HEAD
         // Get source file extension
         $ext = FileBackend::extensionFromPath($srcRel);
         // Create a new temporary file...
         $tmpFile = TempFSFile::factory(wfBaseName($srcRel) . '_', $ext);
         if ($tmpFile) {
             $handle = fopen($tmpFile->getPath(), 'wb');
             if ($handle) {
                 $obj->stream($handle, $this->headersFromParams($params));
                 fclose($handle);
             } else {
                 $tmpFile = null;
                 // couldn't open temp file
             }
         }
     } catch (NoSuchContainerException $e) {
         $tmpFile = null;
         $this->logException($e, __METHOD__, $params);
     } catch (NoSuchObjectException $e) {
         $tmpFile = null;
         $this->logException($e, __METHOD__, $params);
     } catch (InvalidResponseException $e) {
         $tmpFile = null;
         $this->logException($e, __METHOD__, $params);
     } catch (Exception $e) {
         // some other exception?
         $tmpFile = null;
         $this->logException($e, __METHOD__, $params);
     }
     return $tmpFile;
 }
Esempio n. 2
0
 /**
  * @see FileBackendStore::doGetLocalCopyMulti()
  * @return null|TempFSFile
  */
 protected function doGetLocalCopyMulti(array $params)
 {
     $tmpFiles = array();
     $ep = array_diff_key($params, array('srcs' => 1));
     // for error logging
     // Blindly create tmp files and stream to them, catching any exception if the file does
     // not exist. Doing a stat here is useless causes infinite loops in addMissingMetadata().
     foreach (array_chunk($params['srcs'], $params['concurrency']) as $pathBatch) {
         $cfOps = array();
         // (path => CF_Async_Op)
         foreach ($pathBatch as $path) {
             // each path in this concurrent batch
             list($srcCont, $srcRel) = $this->resolveStoragePathReal($path);
             if ($srcRel === null) {
                 $tmpFiles[$path] = null;
                 continue;
             }
             $tmpFile = null;
             try {
                 $sContObj = $this->getContainer($srcCont);
                 $obj = new CF_Object($sContObj, $srcRel, false, false);
                 // skip HEAD
                 // Get source file extension
                 $ext = FileBackend::extensionFromPath($path);
                 // Create a new temporary file...
                 $tmpFile = TempFSFile::factory('localcopy_', $ext);
                 if ($tmpFile) {
                     $handle = fopen($tmpFile->getPath(), 'wb');
                     if ($handle) {
                         $headers = $this->headersFromParams($params);
                         if (count($pathBatch) > 1) {
                             $cfOps[$path] = $obj->stream_async($handle, $headers);
                             $cfOps[$path]->_file_handle = $handle;
                             // close this later
                         } else {
                             $obj->stream($handle, $headers);
                             fclose($handle);
                         }
                     } else {
                         $tmpFile = null;
                     }
                 }
             } catch (NoSuchContainerException $e) {
                 $tmpFile = null;
             } catch (NoSuchObjectException $e) {
                 $tmpFile = null;
             } catch (CloudFilesException $e) {
                 // some other exception?
                 $tmpFile = null;
                 $this->handleException($e, null, __METHOD__, array('src' => $path) + $ep);
             }
             $tmpFiles[$path] = $tmpFile;
         }
         $batch = new CF_Async_Op_Batch($cfOps);
         $cfOps = $batch->execute();
         foreach ($cfOps as $path => $cfOp) {
             try {
                 $cfOp->getLastResponse();
             } catch (NoSuchContainerException $e) {
                 $tmpFiles[$path] = null;
             } catch (NoSuchObjectException $e) {
                 $tmpFiles[$path] = null;
             } catch (CloudFilesException $e) {
                 // some other exception?
                 $tmpFiles[$path] = null;
                 $this->handleException($e, null, __METHOD__, array('src' => $path) + $ep);
             }
             fclose($cfOp->_file_handle);
             // close open handle
         }
     }
     return $tmpFiles;
 }
Esempio n. 3
0
 /**
  * @see FileBackendStore::getLocalCopy()
  * @return null|TempFSFile
  */
 public function getLocalCopy(array $params)
 {
     list($srcCont, $srcRel) = $this->resolveStoragePathReal($params['src']);
     if ($srcRel === null) {
         return null;
     }
     // Blindly create a tmp file and stream to it, catching any exception if the file does
     // not exist. Also, doing a stat here will cause infinite loops when filling metadata.
     $tmpFile = null;
     try {
         $sContObj = $this->getContainer($srcCont);
         $obj = new CF_Object($sContObj, $srcRel, false, false);
         // skip HEAD
         // Get source file extension
         $ext = FileBackend::extensionFromPath($srcRel);
         // Create a new temporary file...
         $tmpFile = TempFSFile::factory('localcopy_', $ext);
         if ($tmpFile) {
             $handle = fopen($tmpFile->getPath(), 'wb');
             if ($handle) {
                 $obj->stream($handle, $this->headersFromParams($params));
                 fclose($handle);
             } else {
                 $tmpFile = null;
                 // couldn't open temp file
             }
         }
     } catch (NoSuchContainerException $e) {
         $tmpFile = null;
     } catch (NoSuchObjectException $e) {
         $tmpFile = null;
     } catch (CloudFilesException $e) {
         // some other exception?
         $tmpFile = null;
         $this->handleException($e, null, __METHOD__, $params);
     }
     return $tmpFile;
 }