From: epriestley Date: Wed, 17 Aug 2016 13:55:48 +0000 (-0700) Subject: Fix handling of View Policy in CLI upload workflow for small, unique files X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=6507be27aeb90fe32ad9d45f97bdd61e173fd378;p=arcanist.git Fix handling of View Policy in CLI upload workflow for small, unique files Summary: Ref T7148. When uploading files from the CLI with a particular view policy, we may not respect it if the file is unique (so the data isn't already known) and small (so it doesn't invoke the chunker). This is rare (and may never have happened outside of testing) because: - production dumps are always larger than the minimum chunk size; - only cluster stuff uses `setViewPolicy()`; - the default policy is "Administrators" anyway, which is safe. However, I caught it in local testing, so fix it up. Test Plan: Used `bin/host upload --file ...` to upload a small, unique file. Verified it uploaded with the correct custom view policy ("No One") rather than the default view policy ("Administrators"). Reviewers: chad Reviewed By: chad Maniphest Tasks: T7148 Differential Revision: https://secure.phabricator.com/D16408 --- diff --git a/src/upload/ArcanistFileUploader.php b/src/upload/ArcanistFileUploader.php index b37b1856..daf4136d 100644 --- a/src/upload/ArcanistFileUploader.php +++ b/src/upload/ArcanistFileUploader.php @@ -116,8 +116,7 @@ final class ArcanistFileUploader extends Phobject { $conduit = $this->conduit; $futures = array(); foreach ($files as $key => $file) { - $params = array( - 'name' => $file->getName(), + $params = $this->getUploadParameters($file) + array( 'contentLength' => $file->getByteSize(), 'contentHash' => $file->getContentHash(), ); @@ -127,11 +126,6 @@ final class ArcanistFileUploader extends Phobject { $params['deleteAfterEpoch'] = $delete_after; } - $view_policy = $file->getViewPolicy(); - if ($view_policy !== null) { - $params['viewPolicy'] = $view_policy; - } - $futures[$key] = $conduit->callMethod('file.allocate', $params); } @@ -294,13 +288,29 @@ final class ArcanistFileUploader extends Phobject { return $conduit->callMethodSynchronous( 'file.upload', - array( - 'name' => $file->getName(), + $this->getUploadParameters($file) + array( 'data_base64' => base64_encode($data), )); } + /** + * Get common parameters for file uploads. + */ + private function getUploadParameters(ArcanistFileDataRef $file) { + $params = array( + 'name' => $file->getName(), + ); + + $view_policy = $file->getViewPolicy(); + if ($view_policy !== null) { + $params['viewPolicy'] = $view_policy; + } + + return $params; + } + + /** * Write a status message. *