Page MenuHomePhabricator

D14056.id.diff
No OneTemporary

D14056.id.diff

diff --git a/src/upload/ArcanistFileUploader.php b/src/upload/ArcanistFileUploader.php
--- a/src/upload/ArcanistFileUploader.php
+++ b/src/upload/ArcanistFileUploader.php
@@ -27,6 +27,7 @@
private $conduit;
private $files;
+ private $config = array();
/* -( Configuring the Uploader )------------------------------------------- */
@@ -78,6 +79,33 @@
}
+ /**
+ * 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 )---------------------------------------------------- */
@@ -116,13 +144,20 @@
$conduit = $this->conduit;
$futures = array();
foreach ($files as $key => $file) {
- $futures[$key] = $conduit->callMethod(
- 'file.allocate',
- array(
- 'name' => $file->getName(),
- 'contentLength' => $file->getByteSize(),
- 'contentHash' => $file->getContentHash(),
- ));
+ $config = idx($this->config, $key, array());
+
+ $params = array(
+ 'name' => $file->getName(),
+ 'contentLength' => $file->getByteSize(),
+ 'contentHash' => $file->getContentHash(),
+ );
+
+ $delete_after = idx($config, 'deleteAfterEpoch');
+ if ($delete_after !== null) {
+ $params['deleteAfterEpoch'] = $delete_after;
+ }
+
+ $futures[$key] = $conduit->callMethod('file.allocate', $params);
}
$iterator = id(new FutureIterator($futures))->limit(4);
diff --git a/src/workflow/ArcanistUploadWorkflow.php b/src/workflow/ArcanistUploadWorkflow.php
--- a/src/workflow/ArcanistUploadWorkflow.php
+++ b/src/workflow/ArcanistUploadWorkflow.php
@@ -32,6 +32,11 @@
'json' => array(
'help' => pht('Output upload information in JSON format.'),
),
+ 'temporary' => array(
+ 'help' => pht(
+ 'Mark the file as temporary. Temporary files will be deleted '.
+ 'automatically after 24 hours.'),
+ ),
'*' => 'paths',
);
}
@@ -51,18 +56,26 @@
}
public function run() {
+ $is_temporary = $this->getArgument('temporary');
+
$conduit = $this->getConduit();
$results = array();
$uploader = id(new ArcanistFileUploader())
->setConduitClient($conduit);
- foreach ($this->paths as $path) {
+ foreach ($this->paths as $key => $path) {
$file = id(new ArcanistFileDataRef())
->setName(basename($path))
->setPath($path);
- $uploader->addFile($file);
+ $uploader->addFile($file, $key);
+
+ if ($is_temporary) {
+ $uploader->setDeleteFileAfterEpoch(
+ $key,
+ time() + phutil_units('24 hours in seconds'));
+ }
}
$files = $uploader->uploadFiles();

File Metadata

Mime Type
text/plain
Expires
Thu, Apr 17, 6:55 PM (3 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7332373
Default Alt Text
D14056.id.diff (3 KB)

Event Timeline