Differential D20614 Diff 49179 src/applications/files/management/PhabricatorFilesManagementIntegrityWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/management/PhabricatorFilesManagementIntegrityWorkflow.php
<?php | <?php | ||||
final class PhabricatorFilesManagementIntegrityWorkflow | final class PhabricatorFilesManagementIntegrityWorkflow | ||||
extends PhabricatorFilesManagementWorkflow { | extends PhabricatorFilesManagementWorkflow { | ||||
protected function didConstruct() { | protected function didConstruct() { | ||||
$this | $arguments = $this->newIteratorArguments(); | ||||
->setName('integrity') | |||||
->setSynopsis(pht('Verify or recalculate file integrity hashes.')) | $arguments[] = array( | ||||
->setArguments( | |||||
array( | |||||
array( | |||||
'name' => 'all', | |||||
'help' => pht('Affect all files.'), | |||||
), | |||||
array( | |||||
'name' => 'strip', | 'name' => 'strip', | ||||
'help' => pht( | 'help' => pht( | ||||
'DANGEROUS. Strip integrity hashes from files. This makes '. | 'DANGEROUS. Strip integrity hashes from files. This makes '. | ||||
'files vulnerable to corruption or tampering.'), | 'files vulnerable to corruption or tampering.'), | ||||
), | ); | ||||
array( | |||||
$arguments[] = array( | |||||
'name' => 'corrupt', | 'name' => 'corrupt', | ||||
'help' => pht( | 'help' => pht( | ||||
'Corrupt integrity hashes for given files. This is intended '. | 'Corrupt integrity hashes for given files. This is intended '. | ||||
'for debugging.'), | 'for debugging.'), | ||||
), | ); | ||||
array( | |||||
$arguments[] = array( | |||||
'name' => 'compute', | 'name' => 'compute', | ||||
'help' => pht( | 'help' => pht( | ||||
'Compute and update integrity hashes for files which do not '. | 'Compute and update integrity hashes for files which do not '. | ||||
'yet have them.'), | 'yet have them.'), | ||||
), | ); | ||||
array( | |||||
$arguments[] = array( | |||||
'name' => 'overwrite', | 'name' => 'overwrite', | ||||
'help' => pht( | 'help' => pht( | ||||
'DANGEROUS. Recompute and update integrity hashes, overwriting '. | 'DANGEROUS. Recompute and update integrity hashes, overwriting '. | ||||
'invalid hashes. This may mark corrupt or dangerous files as '. | 'invalid hashes. This may mark corrupt or dangerous files as '. | ||||
'valid.'), | 'valid.'), | ||||
), | ); | ||||
array( | |||||
$arguments[] = array( | |||||
'name' => 'force', | 'name' => 'force', | ||||
'short' => 'f', | 'short' => 'f', | ||||
'help' => pht( | 'help' => pht( | ||||
'Execute dangerous operations without prompting for '. | 'Execute dangerous operations without prompting for '. | ||||
'confirmation.'), | 'confirmation.'), | ||||
), | ); | ||||
array( | |||||
'name' => 'names', | |||||
'wildcard' => true, | $this | ||||
), | ->setName('integrity') | ||||
)); | ->setSynopsis(pht('Verify or recalculate file integrity hashes.')) | ||||
->setArguments($arguments); | |||||
} | } | ||||
public function execute(PhutilArgumentParser $args) { | public function execute(PhutilArgumentParser $args) { | ||||
$modes = array(); | $modes = array(); | ||||
$is_strip = $args->getArg('strip'); | $is_strip = $args->getArg('strip'); | ||||
if ($is_strip) { | if ($is_strip) { | ||||
$modes[] = 'strip'; | $modes[] = 'strip'; | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | if (!$is_force) { | ||||
if (!phutil_console_confirm(pht('Continue anyway?'))) { | if (!phutil_console_confirm(pht('Continue anyway?'))) { | ||||
throw new PhutilArgumentUsageException(pht('Aborted workflow.')); | throw new PhutilArgumentUsageException(pht('Aborted workflow.')); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
$iterator = $this->buildIterator($args); | $iterator = $this->buildIterator($args); | ||||
if (!$iterator) { | |||||
throw new PhutilArgumentUsageException( | |||||
pht( | |||||
'Either specify a list of files to affect, or use "--all" to '. | |||||
'affect all files.')); | |||||
} | |||||
$failure_count = 0; | $failure_count = 0; | ||||
$total_count = 0; | $total_count = 0; | ||||
foreach ($iterator as $file) { | foreach ($iterator as $file) { | ||||
$total_count++; | $total_count++; | ||||
$display_name = $file->getMonogram(); | $display_name = $file->getMonogram(); | ||||
▲ Show 20 Lines • Show All 189 Lines • Show Last 20 Lines |