예제 #1
0
 /**
  * @param \CF_Container $container
  * @param \CF_Object $object
  */
 function it_should_lazily_fetch_container_before_checksum($connection, $container, $object)
 {
     $connection->get_container('my_container')->willReturn($container)->shouldBeCalled();
     $object->getETag()->willReturn('123m5');
     $container->get_object('filename')->willReturn($object);
     $this->checksum('filename')->shouldReturn('123m5');
 }
예제 #2
0
 /**
  * remove custom mtime metadata
  * @param \CF_Object $obj
  */
 private function resetMTime($obj)
 {
     if (isset($obj->metadata['Mtime'])) {
         $obj->metadata['Mtime'] = -1;
         $obj->sync_metadata();
     }
 }
예제 #3
0
 /**
  * Helper function to create "path" elements for a given Object name
  *
  * Given an Object whos name contains '/' path separators, this function
  * will create the "directory marker" Objects of one byte with the
  * Content-Type of "application/folder".
  *
  * It assumes the last element of the full path is the "real" Object
  * and does NOT create a remote storage Object for that last element.
  */
 function create_paths($path_name)
 {
     if ($path_name[0] == '/') {
         $path_name = mb_substr($path_name, 0, 1);
     }
     $elements = explode('/', $path_name, -1);
     $build_path = "";
     foreach ($elements as $idx => $val) {
         if (!$build_path) {
             $build_path = $val;
         } else {
             $build_path .= "/" . $val;
         }
         $obj = new CF_Object($this, $build_path);
         $obj->content_type = "application/directory";
         $obj->write(".", 1);
     }
 }
예제 #4
0
 /**
  * @see FileBackendStore::getFileHttpUrl()
  * @return string|null
  */
 public function getFileHttpUrl(array $params)
 {
     if ($this->swiftTempUrlKey != '' || $this->rgwS3AccessKey != '' && $this->rgwS3SecretKey != '') {
         list($srcCont, $srcRel) = $this->resolveStoragePathReal($params['src']);
         if ($srcRel === null) {
             return null;
             // invalid path
         }
         try {
             $ttl = isset($params['ttl']) ? $params['ttl'] : 86400;
             $sContObj = $this->getContainer($srcCont);
             $obj = new CF_Object($sContObj, $srcRel, false, false);
             // skip HEAD
             if ($this->swiftTempUrlKey != '') {
                 return $obj->get_temp_url($this->swiftTempUrlKey, $ttl, "GET");
             } else {
                 // give S3 API URL for rgw
                 $expires = time() + $ttl;
                 // Path for signature starts with the bucket
                 $spath = '/' . rawurlencode($srcCont) . '/' . str_replace('%2F', '/', rawurlencode($srcRel));
                 // Calculate the hash
                 $signature = base64_encode(hash_hmac('sha1', "GET\n\n\n{$expires}\n{$spath}", $this->rgwS3SecretKey, true));
                 // See http://s3.amazonaws.com/doc/s3-developer-guide/RESTAuthentication.html.
                 // Note: adding a newline for empty CanonicalizedAmzHeaders does not work.
                 return wfAppendQuery(str_replace('/swift/v1', '', $sContObj->cfs_http->getStorageUrl() . $spath), array('Signature' => $signature, 'Expires' => $expires, 'AWSAccessKeyId' => $this->rgwS3AccessKey));
             }
         } catch (NoSuchContainerException $e) {
         } catch (CloudFilesException $e) {
             // some other exception?
             $this->handleException($e, null, __METHOD__, $params);
         }
     }
     return null;
 }
예제 #5
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;
 }
예제 #6
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;
 }
 /**
  * @see FileBackendStore::getFileHttpUrl()
  * @return string|null
  */
 public function getFileHttpUrl(array $params)
 {
     if ($this->swiftTempUrlKey != '') {
         // temp urls enabled
         list($srcCont, $srcRel) = $this->resolveStoragePathReal($params['src']);
         if ($srcRel === null) {
             return null;
             // invalid path
         }
         try {
             $sContObj = $this->getContainer($srcCont);
             $obj = new CF_Object($sContObj, $srcRel, false, false);
             // skip HEAD
             return $obj->get_temp_url($this->swiftTempUrlKey, 86400, "GET");
         } catch (NoSuchContainerException $e) {
         } catch (CloudFilesException $e) {
             // some other exception?
             $this->handleException($e, null, __METHOD__, $params);
         }
     }
     return null;
 }
 /**
  * @param \CF_Container $container
  * @param \CF_Object $object
  */
 function it_should_calculate_checksum($container, $object)
 {
     $object->getETag()->willReturn('123m5');
     $container->get_object('filename')->willReturn($object);
     $this->checksum('filename')->shouldReturn('123m5');
 }
 protected function _getObjectUrl($filename)
 {
     $obj = new CF_Object($this->_bucket, $filename);
     return $obj->public_uri();
 }
예제 #10
0
 /**
  *
  * Make a dir 
  * package by lazypeople<*****@*****.**>
  */
 function sae_mkdir($path_name)
 {
     if ($path_name[0] == '/') {
         $path_name = mb_substr($path_name, 0, 1);
     }
     $dir_name = $path_name . '/' . $path_name;
     $obj = new CF_Object($this, $dir_name);
     $obj->content_type = "text/plain";
     $obj->write("___sae__dir__tag__");
     return true;
 }
예제 #11
0
 /**
  * Delete file from cloud hosting
  * $containerName = 'img_albums';
  * $cloudFileName = 'banner.jpg';
  *  
  * @author Oleg D.
  */
 function deleteFromCloudHosting($containerName, $cloudFileName)
 {
     include_once '../vendors/rackspace_cloudfiles/cloudfiles.php';
     // Connect to Rackspace
     $Auth = new CF_Authentication(RACKSPACE_CLOUDFILE_USERNAME, RACKSPACE_CLOUDFILE_APIKEY);
     $Auth->authenticate();
     $Connection = new CF_Connection($Auth);
     // Get the container we want to use
     $Container = $Connection->get_container($containerName);
     // check for exists file
     $CheckExistObject = new CF_Object($Container, $cloudFileName);
     if (!$CheckExistObject->exists()) {
         return false;
     }
     // delete file
     return $Container->delete_object($cloudFileName);
 }