Esempio n. 1
0
 /**
  * Fill in any missing object metadata and save it to Swift
  *
  * @param $obj CF_Object
  * @param string $path Storage path to object
  * @return bool Success
  * @throws Exception cloudfiles exceptions
  */
 protected function addMissingMetadata(CF_Object $obj, $path)
 {
     if ($obj->getMetadataValue('Sha1base36') !== null) {
         return true;
         // nothing to do
     }
     wfProfileIn(__METHOD__);
     trigger_error("{$path} was not stored with SHA-1 metadata.", E_USER_WARNING);
     $status = Status::newGood();
     $scopeLockS = $this->getScopedFileLocks(array($path), LockManager::LOCK_UW, $status);
     if ($status->isOK()) {
         $tmpFile = $this->getLocalCopy(array('src' => $path, 'latest' => 1));
         if ($tmpFile) {
             $hash = $tmpFile->getSha1Base36();
             if ($hash !== false) {
                 $obj->setMetadataValues(array('Sha1base36' => $hash));
                 $obj->sync_metadata();
                 // save to Swift
                 wfProfileOut(__METHOD__);
                 return true;
                 // success
             }
         }
     }
     trigger_error("Unable to set SHA-1 metadata for {$path}", E_USER_WARNING);
     $obj->setMetadataValues(array('Sha1base36' => false));
     wfProfileOut(__METHOD__);
     return false;
     // failed
 }