Changeset View
Changeset View
Standalone View
Standalone View
src/upload/ArcanistFileUploader.php
Show First 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | foreach ($files as $key => $file) { | ||||
'contentHash' => $file->getContentHash(), | 'contentHash' => $file->getContentHash(), | ||||
); | ); | ||||
$delete_after = $file->getDeleteAfterEpoch(); | $delete_after = $file->getDeleteAfterEpoch(); | ||||
if ($delete_after !== null) { | if ($delete_after !== null) { | ||||
$params['deleteAfterEpoch'] = $delete_after; | $params['deleteAfterEpoch'] = $delete_after; | ||||
} | } | ||||
// TOOLSETS: This should be a real future, but ConduitEngine and | $futures[$key] = $conduit->newFuture('file.allocate', $params); | ||||
// ConduitCall are currently built oddly and return pretend futures. | |||||
$futures[$key] = new ImmediateFuture( | |||||
$conduit->resolveCall('file.allocate', $params)); | |||||
} | } | ||||
$iterator = id(new FutureIterator($futures))->limit(4); | $iterator = id(new FutureIterator($futures))->limit(4); | ||||
$chunks = array(); | $chunks = array(); | ||||
foreach ($iterator as $key => $future) { | foreach ($iterator as $key => $future) { | ||||
try { | try { | ||||
$result = $future->resolve(); | $result = $future->resolve(); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | /* -( Internals )---------------------------------------------------------- */ | ||||
* Upload missing chunks of a large file by calling `file.uploadchunk` over | * Upload missing chunks of a large file by calling `file.uploadchunk` over | ||||
* Conduit. | * Conduit. | ||||
* | * | ||||
* @task internal | * @task internal | ||||
*/ | */ | ||||
private function uploadChunks(ArcanistFileDataRef $file, $file_phid) { | private function uploadChunks(ArcanistFileDataRef $file, $file_phid) { | ||||
$conduit = $this->conduitEngine; | $conduit = $this->conduitEngine; | ||||
$chunks = $conduit->resolveCall( | $future = $conduit->newFuture( | ||||
'file.querychunks', | 'file.querychunks', | ||||
array( | array( | ||||
'filePHID' => $file_phid, | 'filePHID' => $file_phid, | ||||
)); | )); | ||||
$chunks = $future->resolve(); | |||||
$remaining = array(); | $remaining = array(); | ||||
foreach ($chunks as $chunk) { | foreach ($chunks as $chunk) { | ||||
if (!$chunk['complete']) { | if (!$chunk['complete']) { | ||||
$remaining[] = $chunk; | $remaining[] = $chunk; | ||||
} | } | ||||
} | } | ||||
Show All 20 Lines | private function uploadChunks(ArcanistFileDataRef $file, $file_phid) { | ||||
} | } | ||||
$progress->draw(); | $progress->draw(); | ||||
// TODO: We could do these in parallel to improve upload performance. | // TODO: We could do these in parallel to improve upload performance. | ||||
foreach ($remaining as $chunk) { | foreach ($remaining as $chunk) { | ||||
$data = $file->readBytes($chunk['byteStart'], $chunk['byteEnd']); | $data = $file->readBytes($chunk['byteStart'], $chunk['byteEnd']); | ||||
$conduit->resolveCall( | $future = $conduit->newFuture( | ||||
'file.uploadchunk', | 'file.uploadchunk', | ||||
array( | array( | ||||
'filePHID' => $file_phid, | 'filePHID' => $file_phid, | ||||
'byteStart' => $chunk['byteStart'], | 'byteStart' => $chunk['byteStart'], | ||||
'dataEncoding' => 'base64', | 'dataEncoding' => 'base64', | ||||
'data' => base64_encode($data), | 'data' => base64_encode($data), | ||||
)); | )); | ||||
$future->resolve(); | |||||
$progress->update(1); | $progress->update(1); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Upload an entire file by calling `file.upload` over Conduit. | * Upload an entire file by calling `file.upload` over Conduit. | ||||
* | * | ||||
* @task internal | * @task internal | ||||
*/ | */ | ||||
private function uploadData(ArcanistFileDataRef $file) { | private function uploadData(ArcanistFileDataRef $file) { | ||||
$conduit = $this->conduitEngine; | $conduit = $this->conduitEngine; | ||||
$data = $file->readBytes(0, $file->getByteSize()); | $data = $file->readBytes(0, $file->getByteSize()); | ||||
return $conduit->resolveCall( | $future = $conduit->newFuture( | ||||
'file.upload', | 'file.upload', | ||||
$this->getUploadParameters($file) + array( | $this->getUploadParameters($file) + array( | ||||
'data_base64' => base64_encode($data), | 'data_base64' => base64_encode($data), | ||||
)); | )); | ||||
return $future->resolve(); | |||||
} | } | ||||
/** | /** | ||||
* Get common parameters for file uploads. | * Get common parameters for file uploads. | ||||
*/ | */ | ||||
private function getUploadParameters(ArcanistFileDataRef $file) { | private function getUploadParameters(ArcanistFileDataRef $file) { | ||||
$params = array( | $params = array( | ||||
Show All 22 Lines |