1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-30 01:10:58 +01:00

Fix error detection for "ls-tree" output

Summary: Fixes T4223. The output of `ls-tree` is partially delimited by spaces
and partially delimited by `\t`. The code I added in D7744 to help debug the
issue in T4159 doesn't work properly for files with 7 or more bytes in their
filesize, because the internals use `%7s`.

Auditors: btrahan
This commit is contained in:
epriestley 2013-12-11 07:13:16 -08:00
parent b8b7bf8ad9
commit 052c83a613

View file

@ -100,19 +100,22 @@ final class ConduitAPI_diffusion_browsequery_Method
$results = array();
foreach (explode("\0", rtrim($stdout)) as $line) {
if (substr_count($line, ' ') < 4) {
// NOTE: Limit to 5 components so we parse filenames with spaces in them
// correctly.
// NOTE: The output uses a mixture of tabs and one-or-more spaces to
// delimit fields.
$parts = preg_split('/\s+/', $line, 5);
if (count($parts) < 5) {
throw new Exception(
pht(
'Expected "<mode> <type> <hash> <size> <name>", for ls-tree of '.
'Expected "<mode> <type> <hash> <size>\t<name>", for ls-tree of '.
'"%s:%s", got: %s',
$commit,
$path,
$line));
}
// NOTE: Limit to 5 components so we parse filenames with spaces in them
// correctly.
list($mode, $type, $hash, $size, $name) = preg_split('/\s+/', $line, 5);
list($mode, $type, $hash, $size, $name) = $parts;
$path_result = new DiffusionRepositoryPath();