Differential D17625 Diff 42394 src/applications/files/management/PhabricatorFilesManagementCatWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/management/PhabricatorFilesManagementCatWorkflow.php
Show All 14 Lines | $this | ||||
'help' => pht('Begin printing at a specific offset.'), | 'help' => pht('Begin printing at a specific offset.'), | ||||
), | ), | ||||
array( | array( | ||||
'name' => 'end', | 'name' => 'end', | ||||
'param' => 'bytes', | 'param' => 'bytes', | ||||
'help' => pht('End printing at a specific offset.'), | 'help' => pht('End printing at a specific offset.'), | ||||
), | ), | ||||
array( | array( | ||||
'name' => 'salvage', | |||||
'help' => pht( | |||||
'DANGEROUS. Attempt to salvage file content even if the '. | |||||
'integrity check fails. If an adversary has tampered with '. | |||||
'the file, the conent may be unsafe.'), | |||||
), | |||||
array( | |||||
'name' => 'names', | 'name' => 'names', | ||||
'wildcard' => true, | 'wildcard' => true, | ||||
), | ), | ||||
)); | )); | ||||
} | } | ||||
public function execute(PhutilArgumentParser $args) { | public function execute(PhutilArgumentParser $args) { | ||||
$console = PhutilConsole::getConsole(); | $console = PhutilConsole::getConsole(); | ||||
$names = $args->getArg('names'); | $names = $args->getArg('names'); | ||||
if (count($names) > 1) { | if (count($names) > 1) { | ||||
throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
pht('Specify exactly one file to print, like "%s".', 'F123')); | pht('Specify exactly one file to print, like "%s".', 'F123')); | ||||
} else if (!$names) { | } else if (!$names) { | ||||
throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
pht('Specify a file to print, like "%s".', 'F123')); | pht('Specify a file to print, like "%s".', 'F123')); | ||||
} | } | ||||
$file = head($this->loadFilesWithNames($names)); | $file = head($this->loadFilesWithNames($names)); | ||||
$begin = $args->getArg('begin'); | $begin = $args->getArg('begin'); | ||||
$end = $args->getArg('end'); | $end = $args->getArg('end'); | ||||
$file->makeEphemeral(); | |||||
// If we're running in "salvage" mode, wipe out any integrity hash which | |||||
// may be present. This makes us read file data without performing an | |||||
// integrity check. | |||||
$salvage = $args->getArg('salvage'); | |||||
if ($salvage) { | |||||
$file->setIntegrityHash(null); | |||||
} | |||||
try { | |||||
$iterator = $file->getFileDataIterator($begin, $end); | $iterator = $file->getFileDataIterator($begin, $end); | ||||
foreach ($iterator as $data) { | foreach ($iterator as $data) { | ||||
echo $data; | echo $data; | ||||
} | } | ||||
} catch (PhabricatorFileIntegrityException $ex) { | |||||
throw new PhutilArgumentUsageException( | |||||
pht( | |||||
'File data integrity check failed. Use "--salvage" to bypass '. | |||||
'integrity checks. This flag is dangerous, use it at your own '. | |||||
'risk. Underlying error: %s', | |||||
$ex->getMessage())); | |||||
} | |||||
return 0; | return 0; | ||||
} | } | ||||
} | } |