Page MenuHomePhabricator

D17617.id42380.diff
No OneTemporary

D17617.id42380.diff

diff --git a/src/applications/auth/controller/PhabricatorAuthSSHKeyGenerateController.php b/src/applications/auth/controller/PhabricatorAuthSSHKeyGenerateController.php
--- a/src/applications/auth/controller/PhabricatorAuthSSHKeyGenerateController.php
+++ b/src/applications/auth/controller/PhabricatorAuthSSHKeyGenerateController.php
@@ -24,7 +24,7 @@
$keys = PhabricatorSSHKeyGenerator::generateKeypair();
list($public_key, $private_key) = $keys;
- $file = PhabricatorFile::buildFromFileDataOrHash(
+ $file = PhabricatorFile::newFromFileData(
$private_key,
array(
'name' => $default_name.'.key',
diff --git a/src/applications/differential/controller/DifferentialRevisionViewController.php b/src/applications/differential/controller/DifferentialRevisionViewController.php
--- a/src/applications/differential/controller/DifferentialRevisionViewController.php
+++ b/src/applications/differential/controller/DifferentialRevisionViewController.php
@@ -889,15 +889,15 @@
}
$file_name .= 'diff';
- $file = PhabricatorFile::buildFromFileDataOrHash(
- $raw_diff,
- array(
- 'name' => $file_name,
- 'ttl.relative' => phutil_units('24 hours in seconds'),
- 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE,
- ));
-
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
+ $file = PhabricatorFile::newFromFileData(
+ $raw_diff,
+ array(
+ 'name' => $file_name,
+ 'ttl.relative' => phutil_units('24 hours in seconds'),
+ 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE,
+ ));
+
$file->attachToObject($revision->getPHID());
unset($unguarded);
diff --git a/src/applications/files/storage/PhabricatorFile.php b/src/applications/files/storage/PhabricatorFile.php
--- a/src/applications/files/storage/PhabricatorFile.php
+++ b/src/applications/files/storage/PhabricatorFile.php
@@ -197,44 +197,6 @@
}
- /**
- * Given a block of data, try to load an existing file with the same content
- * if one exists. If it does not, build a new file.
- *
- * This method is generally used when we have some piece of semi-trusted data
- * like a diff or a file from a repository that we want to show to the user.
- * We can't just dump it out because it may be dangerous for any number of
- * reasons; instead, we need to serve it through the File abstraction so it
- * ends up on the CDN domain if one is configured and so on. However, if we
- * simply wrote a new file every time we'd potentially end up with a lot
- * of redundant data in file storage.
- *
- * To solve these problems, we use file storage as a cache and reuse the
- * same file again if we've previously written it.
- *
- * NOTE: This method unguards writes.
- *
- * @param string Raw file data.
- * @param dict Dictionary of file information.
- */
- public static function buildFromFileDataOrHash(
- $data,
- array $params = array()) {
-
- $file = id(new PhabricatorFile())->loadOneWhere(
- 'name = %s AND contentHash = %s LIMIT 1',
- idx($params, 'name'),
- self::hashFileContent($data));
-
- if (!$file) {
- $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
- $file = self::newFromFileData($data, $params);
- unset($unguarded);
- }
-
- return $file;
- }
-
public static function newFileFromContentHash($hash, array $params) {
// Check to see if a file with same contentHash exist
$file = id(new PhabricatorFile())->loadOneWhere(
diff --git a/src/applications/phragment/conduit/PhragmentGetPatchConduitAPIMethod.php b/src/applications/phragment/conduit/PhragmentGetPatchConduitAPIMethod.php
--- a/src/applications/phragment/conduit/PhragmentGetPatchConduitAPIMethod.php
+++ b/src/applications/phragment/conduit/PhragmentGetPatchConduitAPIMethod.php
@@ -174,12 +174,15 @@
unset($patches[$key]['fileOld']);
unset($patches[$key]['fileNew']);
- $file = PhabricatorFile::buildFromFileDataOrHash(
- $data,
- array(
- 'name' => 'patch.dmp',
- 'ttl.relative' => phutil_units('24 hours in seconds'),
- ));
+ $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
+ $file = PhabricatorFile::newFromFileData(
+ $data,
+ array(
+ 'name' => 'patch.dmp',
+ 'ttl.relative' => phutil_units('24 hours in seconds'),
+ ));
+ unset($unguarded);
+
$patches[$key]['patchURI'] = $file->getDownloadURI();
}
diff --git a/src/applications/phragment/controller/PhragmentPatchController.php b/src/applications/phragment/controller/PhragmentPatchController.php
--- a/src/applications/phragment/controller/PhragmentPatchController.php
+++ b/src/applications/phragment/controller/PhragmentPatchController.php
@@ -78,15 +78,15 @@
$return = $request->getStr('return');
}
- $result = PhabricatorFile::buildFromFileDataOrHash(
- $patch,
- array(
- 'name' => $name,
- 'mime-type' => 'text/plain',
- 'ttl.relative' => phutil_units('24 hours in seconds'),
- ));
-
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
+ $result = PhabricatorFile::newFromFileData(
+ $patch,
+ array(
+ 'name' => $name,
+ 'mime-type' => 'text/plain',
+ 'ttl.relative' => phutil_units('24 hours in seconds'),
+ ));
+
$result->attachToObject($version_b->getFragmentPHID());
unset($unguarded);
diff --git a/src/applications/phragment/controller/PhragmentZIPController.php b/src/applications/phragment/controller/PhragmentZIPController.php
--- a/src/applications/phragment/controller/PhragmentZIPController.php
+++ b/src/applications/phragment/controller/PhragmentZIPController.php
@@ -100,14 +100,15 @@
}
$data = Filesystem::readFile((string)$temp);
- $file = PhabricatorFile::buildFromFileDataOrHash(
- $data,
- array(
- 'name' => $zip_name,
- 'ttl.relative' => phutil_units('24 hours in seconds'),
- ));
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
+ $file = PhabricatorFile::newFromFileData(
+ $data,
+ array(
+ 'name' => $zip_name,
+ 'ttl.relative' => phutil_units('24 hours in seconds'),
+ ));
+
$file->attachToObject($fragment->getPHID());
unset($unguarded);

File Metadata

Mime Type
text/plain
Expires
Sun, Jul 27, 4:03 PM (1 h, 56 m ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
8634206
Default Alt Text
D17617.id42380.diff (6 KB)

Event Timeline