3 final class PhabricatorFilesManagementCatWorkflow
4 extends PhabricatorFilesManagementWorkflow
{
6 protected function didConstruct() {
9 ->setSynopsis(pht('Print the contents of a file.'))
15 'help' => pht('Begin printing at a specific offset.'),
20 'help' => pht('End printing at a specific offset.'),
25 'DANGEROUS. Attempt to salvage file content even if the '.
26 'integrity check fails. If an adversary has tampered with '.
27 'the file, the content may be unsafe.'),
36 public function execute(PhutilArgumentParser
$args) {
37 $console = PhutilConsole
::getConsole();
39 $names = $args->getArg('names');
40 if (count($names) > 1) {
41 throw new PhutilArgumentUsageException(
42 pht('Specify exactly one file to print, like "%s".', 'F123'));
44 throw new PhutilArgumentUsageException(
45 pht('Specify a file to print, like "%s".', 'F123'));
48 $file = head($this->loadFilesWithNames($names));
50 $begin = $args->getArg('begin');
51 $end = $args->getArg('end');
53 $file->makeEphemeral();
55 // If we're running in "salvage" mode, wipe out any integrity hash which
56 // may be present. This makes us read file data without performing an
58 $salvage = $args->getArg('salvage');
60 $file->setIntegrityHash(null);
64 $iterator = $file->getFileDataIterator($begin, $end);
65 foreach ($iterator as $data) {
68 } catch (PhabricatorFileIntegrityException
$ex) {
69 throw new PhutilArgumentUsageException(
71 'File data integrity check failed. Use "--salvage" to bypass '.
72 'integrity checks. This flag is dangerous, use it at your own '.
73 'risk. Underlying error: %s',