]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Fix handling of View Policy in CLI upload workflow for small, unique files
authorepriestley <git@epriestley.com>
Wed, 17 Aug 2016 13:55:48 +0000 (06:55 -0700)
committerepriestley <git@epriestley.com>
Wed, 17 Aug 2016 16:04:01 +0000 (09:04 -0700)
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

src/upload/ArcanistFileUploader.php

index b37b1856c6ff1cface2766afbe0da6d9069ffb16..daf4136d1df399580b83db71998da63a9ec1a289 100644 (file)
@@ -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.
    *