]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve temporary file upload API and add viewPolicy support
authorepriestley <git@epriestley.com>
Mon, 7 Sep 2015 19:44:59 +0000 (12:44 -0700)
committerepriestley <git@epriestley.com>
Mon, 7 Sep 2015 19:44:59 +0000 (12:44 -0700)
Summary: Ref T7148. In D14056, I let `arc upload` upload temporary files, but this is a better way to do some of the internals. Also add support for setting a `viewPolicy`.

Test Plan: Used `arc upload`, `arc upload --temporary`.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T7148

Differential Revision: https://secure.phabricator.com/D14075

src/upload/ArcanistFileDataRef.php
src/upload/ArcanistFileUploader.php
src/workflow/ArcanistUploadWorkflow.php

index 795fbd672123714253e1feafdf1ea0ad991e4e71..318418ece3d3950477ffdc0c111172076877214f 100644 (file)
@@ -27,6 +27,8 @@ final class ArcanistFileDataRef extends Phobject {
   private $errors = array();
   private $phid;
   private $fileHandle;
+  private $deleteAfterEpoch;
+  private $viewPolicy;
 
 
 /* -(  Configuring File References  )---------------------------------------- */
@@ -107,6 +109,48 @@ final class ArcanistFileDataRef extends Phobject {
   }
 
 
+  /**
+   * @task config
+   */
+  public function setViewPolicy($view_policy) {
+    $this->viewPolicy = $view_policy;
+    return $this;
+  }
+
+
+  /**
+   * @task config
+   */
+  public function getViewPolicy() {
+    return $this->viewPolicy;
+  }
+
+
+  /**
+   * Configure a file to be temporary instead of permanent.
+   *
+   * By default, files are retained indefinitely until explicitly deleted. If
+   * you want to upload a temporary file instead, you can specify an epoch
+   * timestamp. The file will be deleted after this time.
+   *
+   * @param int Epoch timestamp to retain the file until.
+   * @return this
+   * @task config
+   */
+  public function setDeleteAfterEpoch($epoch) {
+    $this->deleteAfterEpoch = $epoch;
+    return $this;
+  }
+
+
+  /**
+   * @task config
+   */
+  public function getDeleteAfterEpoch() {
+    return $this->deleteAfterEpoch;
+  }
+
+
 /* -(  Handling Upload Results  )-------------------------------------------- */
 
 
index ba96077581e80ad2937e1427c6057aa1c1435977..27ec8d347a48b0103a41b4c381507b2deb0ed7a3 100644 (file)
@@ -27,7 +27,6 @@ final class ArcanistFileUploader extends Phobject {
 
   private $conduit;
   private $files;
-  private $config = array();
 
 
 /* -(  Configuring the Uploader  )------------------------------------------- */
@@ -79,33 +78,6 @@ final class ArcanistFileUploader extends Phobject {
   }
 
 
-  /**
-   * Configure a file to be temporary instead of permanent.
-   *
-   * By default, files are retained indefinitely until explicitly deleted. If
-   * you want to upload a temporary file instead, you can specify an epoch
-   * timestamp. The file will be deleted after this time.
-   *
-   * @param string Key identifying the file you want to make temporary, as
-   *   passed to @{method:addFile}.
-   * @param int Epoch timestamp to retain the file until.
-   * @return this
-   * @task add
-   */
-  public function setDeleteFileAfterEpoch($file_key, $epoch) {
-    if (empty($this->files[$file_key])) {
-      throw new Exception(
-        pht(
-          'No file with given key ("%s") has been added to this uploader.',
-          $file_key));
-    }
-
-    $this->config[$file_key]['deleteAfterEpoch'] = $epoch;
-
-    return $this;
-  }
-
-
 /* -(  Uploading Files  )---------------------------------------------------- */
 
 
@@ -144,19 +116,22 @@ final class ArcanistFileUploader extends Phobject {
     $conduit = $this->conduit;
     $futures = array();
     foreach ($files as $key => $file) {
-      $config = idx($this->config, $key, array());
-
       $params = array(
         'name' => $file->getName(),
         'contentLength' => $file->getByteSize(),
         'contentHash' => $file->getContentHash(),
       );
 
-      $delete_after = idx($config, 'deleteAfterEpoch');
+      $delete_after = $file->getDeleteAfterEpoch();
       if ($delete_after !== null) {
         $params['deleteAfterEpoch'] = $delete_after;
       }
 
+      $view_policy = $file->getViewPolicy();
+      if ($view_policy !== null) {
+        $params['viewPolicy'] = $view_policy;
+      }
+
       $futures[$key] = $conduit->callMethod('file.allocate', $params);
     }
 
index b4414a398196df959fd011319dde36c22c4f7a66..a31ce0f08138c01ae203e1f27c20107708f8ecfe 100644 (file)
@@ -69,13 +69,12 @@ EOTEXT
         ->setName(basename($path))
         ->setPath($path);
 
-      $uploader->addFile($file, $key);
-
       if ($is_temporary) {
-        $uploader->setDeleteFileAfterEpoch(
-          $key,
-          time() + phutil_units('24 hours in seconds'));
+        $expires_at = time() + phutil_units('24 hours in seconds');
+        $file->setDeleteAfterEpoch($expires_at);
       }
+
+      $uploader->addFile($file);
     }
 
     $files = $uploader->uploadFiles();