public function testChecksumMD5() { if ($this->atmosMajorMinor < 2.1) { $this->markTestSkipped("Requires Atmos >= 2.1.0"); return; } $ck = new Checksum('MD5'); $ck->update($this->CHECK_STRING_1); PHPUnit_Framework_Assert::assertEquals('MD5' . $this->CHECK_STRING_1_OFFSET . $this->CHECK_STRING_1_MD5, "{$ck}", "value of 'checksum' wrong"); // Incremental $ck = new Checksum('MD5'); $ck->update($this->CHECK_STRING_1a); PHPUnit_Framework_Assert::assertEquals($this->CHECK_STRING_1a_MD5, $ck->getHashValue()); $ck->update($this->CHECK_STRING_1b); PHPUnit_Framework_Assert::assertEquals($this->CHECK_STRING_1_MD5, $ck->getHashValue()); PHPUnit_Framework_Assert::assertEquals('MD5' . $this->CHECK_STRING_1_OFFSET . $this->CHECK_STRING_1_MD5, "{$ck}", "value of 'checksum' wrong"); }
/** * Updates an object in the cloud. * @param Identifier $id The ID of the object to update * @param Acl $acl Access control list for the new object. Optional, default * is NULL. * @param MetadataList $metadata Metadata list for the new object. Optional, * default is NULL. * @param Extent $extent The extent of the object to update. If extent * is null or ALL_CONTENT and $data is not, the entire object will be * replaced. If $data is null, $extent must also be null. * @param string $data The data of the object. May be appended * to later. Optional, default is NULL (no content). If data is null, * the extent must also be null. * @param string $mimeType the MIME type of the content. Optional, * may be null. If $data is non-null and $mimeType is null, the MIME * type will default to application/octet-stream. * @param Checksum $checksum if not null, use the Checksum object to compute * the checksum for the update object request. If appending * to the object with subsequent requests, use the same * checksum object for each request. * @throws EsuException if the request fails. */ public function updateObject($id, $acl = null, $metadata = null, $extent = null, $data = null, $mimeType = null, $checksum = null) { // Build the request $resource = $this->getResourcePath($this->context, $id); $req = $this->buildRequest($resource, null); $headers = array(); if ($mimeType == null && $data != null) { $mimeType = 'application/octet-stream'; } if (!empty($mimeType)) { $headers['Content-Type'] = $mimeType; } $headers['x-emc-uid'] = $this->uid; // Process metadata if ($metadata != null) { $this->processMetadata($metadata, $headers); } if ($this->utf8) { $headers['x-emc-utf8'] = 'true'; } if (is_a($id, 'Atmos\\Keypool')) { $headers['x-emc-pool'] = $id->getPool(); } // Check extent / data requirements if ($data == null && $extent != null) { throw new EsuException('Cannot specify an extent without data'); } // Add extent if needed if ($extent != null && $extent != Extent::$ALL_CONTENT) { // Need to do bcmath because the value might be > 4GB $end = bcadd($extent->getOffset(), $extent->getSize()); $end = bcsub($end, 1); $headers['Range'] = 'Bytes=' . $extent->getOffset() . '-' . $end; } if (isset($headers['x-emc-meta'])) { $this->trace('meta ' . $headers['x-emc-meta']); } // Add acl if ($acl != null) { $this->processAcl($acl, $headers); } // Process data if ($data != null) { $req->setBody($data); } else { $req->setBody(''); } // Process checksum if ($checksum != null) { if ($data != null) { $checksum->update($data); } $headers['x-emc-wschecksum'] = '' . $checksum; } $headers['Date'] = gmdate('r'); // Sign and send the request $this->signRequest($req, 'PUT', $resource, $headers, $data); try { $response = @$req->send(); } catch (HTTP_Request2_Exception $e) { throw new EsuException('Sending request failed: ' . $e->__toString()); } // Return the response if ($response->getStatus() > 299) { $this->handleError($response); } }