Page MenuHomePhabricator

D17619.id.diff
No OneTemporary

D17619.id.diff

diff --git a/src/applications/files/conduit/FileAllocateConduitAPIMethod.php b/src/applications/files/conduit/FileAllocateConduitAPIMethod.php
--- a/src/applications/files/conduit/FileAllocateConduitAPIMethod.php
+++ b/src/applications/files/conduit/FileAllocateConduitAPIMethod.php
@@ -36,23 +36,26 @@
$properties = array(
'name' => $name,
'authorPHID' => $viewer->getPHID(),
- 'viewPolicy' => $view_policy,
'isExplicitUpload' => true,
);
+ if ($view_policy !== null) {
+ $properties['viewPolicy'] = $view_policy;
+ }
+
$ttl = $request->getValue('deleteAfterEpoch');
if ($ttl) {
$properties['ttl.absolute'] = $ttl;
}
$file = null;
- if ($hash) {
+ if ($hash !== null) {
$file = PhabricatorFile::newFileFromContentHash(
$hash,
$properties);
}
- if ($hash && !$file) {
+ if ($hash !== null && !$file) {
$chunked_hash = PhabricatorChunkedFileStorageEngine::getChunkedHash(
$viewer,
$hash);
@@ -103,7 +106,7 @@
if ($chunk_engines) {
$chunk_properties = $properties;
- if ($hash) {
+ if ($hash !== null) {
$chunk_properties += array(
'chunkedHash' => $chunked_hash,
);
diff --git a/src/applications/files/conduit/FileUploadConduitAPIMethod.php b/src/applications/files/conduit/FileUploadConduitAPIMethod.php
--- a/src/applications/files/conduit/FileUploadConduitAPIMethod.php
+++ b/src/applications/files/conduit/FileUploadConduitAPIMethod.php
@@ -27,21 +27,27 @@
$viewer = $request->getUser();
$name = $request->getValue('name');
- $can_cdn = $request->getValue('canCDN');
+ $can_cdn = (bool)$request->getValue('canCDN');
$view_policy = $request->getValue('viewPolicy');
$data = $request->getValue('data_base64');
$data = $this->decodeBase64($data);
- $file = PhabricatorFile::newFromFileData(
- $data,
- array(
- 'name' => $name,
- 'authorPHID' => $viewer->getPHID(),
- 'viewPolicy' => $view_policy,
- 'canCDN' => $can_cdn,
- 'isExplicitUpload' => true,
- ));
+ $params = array(
+ 'authorPHID' => $viewer->getPHID(),
+ 'canCDN' => $can_cdn,
+ 'isExplicitUpload' => true,
+ );
+
+ if ($name !== null) {
+ $params['name'] = $name;
+ }
+
+ if ($view_policy !== null) {
+ $params['viewPolicy'] = $view_policy;
+ }
+
+ $file = PhabricatorFile::newFromFileData($data, $params);
return $file->getPHID();
}
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
@@ -198,39 +198,42 @@
public static function newFileFromContentHash($hash, array $params) {
- // Check to see if a file with same contentHash exist
+ if ($hash === null) {
+ return null;
+ }
+
+ // Check to see if a file with same hash already exists.
$file = id(new PhabricatorFile())->loadOneWhere(
'contentHash = %s LIMIT 1',
$hash);
+ if (!$file) {
+ return null;
+ }
- if ($file) {
- $copy_of_storage_engine = $file->getStorageEngine();
- $copy_of_storage_handle = $file->getStorageHandle();
- $copy_of_storage_format = $file->getStorageFormat();
- $copy_of_storage_properties = $file->getStorageProperties();
- $copy_of_byte_size = $file->getByteSize();
- $copy_of_mime_type = $file->getMimeType();
-
- $new_file = self::initializeNewFile();
+ $copy_of_storage_engine = $file->getStorageEngine();
+ $copy_of_storage_handle = $file->getStorageHandle();
+ $copy_of_storage_format = $file->getStorageFormat();
+ $copy_of_storage_properties = $file->getStorageProperties();
+ $copy_of_byte_size = $file->getByteSize();
+ $copy_of_mime_type = $file->getMimeType();
- $new_file->setByteSize($copy_of_byte_size);
+ $new_file = self::initializeNewFile();
- $new_file->setContentHash($hash);
- $new_file->setStorageEngine($copy_of_storage_engine);
- $new_file->setStorageHandle($copy_of_storage_handle);
- $new_file->setStorageFormat($copy_of_storage_format);
- $new_file->setStorageProperties($copy_of_storage_properties);
- $new_file->setMimeType($copy_of_mime_type);
- $new_file->copyDimensions($file);
+ $new_file->setByteSize($copy_of_byte_size);
- $new_file->readPropertiesFromParameters($params);
+ $new_file->setContentHash($hash);
+ $new_file->setStorageEngine($copy_of_storage_engine);
+ $new_file->setStorageHandle($copy_of_storage_handle);
+ $new_file->setStorageFormat($copy_of_storage_format);
+ $new_file->setStorageProperties($copy_of_storage_properties);
+ $new_file->setMimeType($copy_of_mime_type);
+ $new_file->copyDimensions($file);
- $new_file->save();
+ $new_file->readPropertiesFromParameters($params);
- return $new_file;
- }
+ $new_file->save();
- return $file;
+ return $new_file;
}
public static function newChunkedFile(
@@ -353,7 +356,9 @@
}
$file->setByteSize(strlen($data));
- $file->setContentHash(self::hashFileContent($data));
+
+ $hash = self::hashFileContent($data);
+ $file->setContentHash($hash);
$file->setStorageEngine($engine_identifier);
$file->setStorageHandle($data_handle);
@@ -379,10 +384,12 @@
public static function newFromFileData($data, array $params = array()) {
$hash = self::hashFileContent($data);
- $file = self::newFileFromContentHash($hash, $params);
- if ($file) {
- return $file;
+ if ($hash !== null) {
+ $file = self::newFileFromContentHash($hash, $params);
+ if ($file) {
+ return $file;
+ }
}
return self::buildFromFileData($data, $params);
@@ -710,9 +717,8 @@
}
}
-
public static function hashFileContent($data) {
- return sha1($data);
+ return null;
}
public function loadFileData() {
diff --git a/src/applications/files/storage/__tests__/PhabricatorFileTestCase.php b/src/applications/files/storage/__tests__/PhabricatorFileTestCase.php
--- a/src/applications/files/storage/__tests__/PhabricatorFileTestCase.php
+++ b/src/applications/files/storage/__tests__/PhabricatorFileTestCase.php
@@ -301,6 +301,11 @@
$data = Filesystem::readRandomCharacters(64);
+ $hash = PhabricatorFile::hashFileContent($data);
+ if ($hash === null) {
+ $this->assertSkipped(pht('File content hashing is not available.'));
+ }
+
$params = array(
'name' => 'test.dat',
'storageEngines' => array(

File Metadata

Mime Type
text/plain
Expires
Tue, May 14, 7:26 PM (2 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6293761
Default Alt Text
D17619.id.diff (6 KB)

Event Timeline