Differential D15072 Diff 36395 src/applications/diffusion/query/filecontent/DiffusionFileContentQuery.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/query/filecontent/DiffusionFileContentQuery.php
| Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | if ($this->getTimeout()) { | ||||
| $future->setTimeout($this->getTimeout()); | $future->setTimeout($this->getTimeout()); | ||||
| } | } | ||||
| $byte_limit = $this->getByteLimit(); | $byte_limit = $this->getByteLimit(); | ||||
| if ($byte_limit) { | if ($byte_limit) { | ||||
| $future->setStdoutSizeLimit($byte_limit + 1); | $future->setStdoutSizeLimit($byte_limit + 1); | ||||
| } | } | ||||
| $drequest = $this->getRequest(); | |||||
| $name = basename($drequest->getPath()); | |||||
| $ttl = PhabricatorTime::getNow() + phutil_units('48 hours in seconds'); | |||||
| try { | try { | ||||
| $file_content = $this->resolveFileContentFuture($future); | $threshold = PhabricatorFileStorageEngine::getChunkThreshold(); | ||||
| $future->setReadBufferSize($threshold); | |||||
| $source = id(new PhabricatorExecFutureFileUploadSource()) | |||||
| ->setName($name) | |||||
| ->setTTL($ttl) | |||||
| ->setViewPolicy(PhabricatorPolicies::POLICY_NOONE) | |||||
| ->setExecFuture($future); | |||||
| $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | |||||
| $file = $source->uploadFile(); | |||||
| unset($unguarded); | |||||
| } catch (CommandException $ex) { | } catch (CommandException $ex) { | ||||
| if (!$future->getWasKilledByTimeout()) { | if (!$future->getWasKilledByTimeout()) { | ||||
| throw $ex; | throw $ex; | ||||
| } | } | ||||
| $this->didHitTimeLimit = true; | $this->didHitTimeLimit = true; | ||||
| $file_content = null; | $file = null; | ||||
| } | } | ||||
| if ($byte_limit && (strlen($file_content) > $byte_limit)) { | if ($byte_limit && ($file->getByteSize() > $byte_limit)) { | ||||
| $this->didHitByteLimit = true; | $this->didHitByteLimit = true; | ||||
| $file_content = null; | |||||
| $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | |||||
| id(new PhabricatorDestructionEngine()) | |||||
| ->destroyObject($file); | |||||
| unset($unguarded); | |||||
| $file = null; | |||||
| } | } | ||||
| return $file_content; | return $file; | ||||
| } | } | ||||
| } | } | ||||