1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 08:42:41 +01:00

Fix an issue where "bin/differential migrate-hunk" could decompress data

Summary:
Fixes T12986. I caught this bug in the changes from D18584: when we moved a large hunk to file storage, we would decompress it but keep the "deflated" flag. This could cause confusion when loading it later. I missed this in testing since I wasn't exhaustive enough in checking hunks and didn't run into a compressed one.

Instead of compressing on `save()`, compress during the normal workflow.

We currently never advise users to run this workflow so I didn't bother trying to clean up possible existing migrations.

Test Plan:
  - Ran `bin/differential migrate-hunk` on compressed hunks, moving them to and from file storage. Saw them work correctly and remain compressed.
  - Created new small (uncompressed) and large (compressed) hunks, verified they work properly and get compressed (if applicable).
  - Used `bin/cache purge --caches changeset` to clear changeset caches and make sure the actual table was being hit.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T12986

Differential Revision: https://secure.phabricator.com/D18624
This commit is contained in:
epriestley 2017-09-18 12:13:11 -07:00
parent 3ad727ba78
commit 156adccef0

View file

@ -51,8 +51,11 @@ final class DifferentialModernHunk extends DifferentialHunk {
$this->dataEncoding = $this->detectEncodingForStorage($text); $this->dataEncoding = $this->detectEncodingForStorage($text);
$this->dataType = self::DATATYPE_TEXT; $this->dataType = self::DATATYPE_TEXT;
$this->dataFormat = self::DATAFORMAT_RAW;
$this->data = $text; list($format, $data) = $this->formatDataForStorage($text);
$this->dataFormat = $format;
$this->data = $data;
return $this; return $this;
} }
@ -68,24 +71,13 @@ final class DifferentialModernHunk extends DifferentialHunk {
return $this; return $this;
} }
public function save() { private function formatDataForStorage($data) {
$type = $this->getDataType();
$format = $this->getDataFormat();
// Before saving the data, attempt to compress it.
if ($type == self::DATATYPE_TEXT) {
if ($format == self::DATAFORMAT_RAW) {
$data = $this->getData();
$deflated = PhabricatorCaches::maybeDeflateData($data); $deflated = PhabricatorCaches::maybeDeflateData($data);
if ($deflated !== null) { if ($deflated !== null) {
$this->data = $deflated; return array(self::DATAFORMAT_DEFLATED, $deflated);
$this->dataFormat = self::DATAFORMAT_DEFLATED;
}
}
} }
return parent::save(); return array(self::DATAFORMAT_RAW, $data);
} }
public function saveAsText() { public function saveAsText() {
@ -99,7 +91,10 @@ final class DifferentialModernHunk extends DifferentialHunk {
$raw_data = $this->getRawData(); $raw_data = $this->getRawData();
$this->setDataType(self::DATATYPE_TEXT); $this->setDataType(self::DATATYPE_TEXT);
$this->setData($raw_data);
list($format, $data) = $this->formatDataForStorage($raw_data);
$this->setDataFormat($format);
$this->setData($data);
$result = $this->save(); $result = $this->save();
@ -118,8 +113,11 @@ final class DifferentialModernHunk extends DifferentialHunk {
$raw_data = $this->getRawData(); $raw_data = $this->getRawData();
list($format, $data) = $this->formatDataForStorage($raw_data);
$this->setDataFormat($format);
$file = PhabricatorFile::newFromFileData( $file = PhabricatorFile::newFromFileData(
$raw_data, $data,
array( array(
'name' => 'differential-hunk', 'name' => 'differential-hunk',
'mime-type' => 'application/octet-stream', 'mime-type' => 'application/octet-stream',