Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/du.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ function coreutilsDuBytes(array $stat, bool $apparent, string $name, array &$res
$value = $apparent ? ($stat['size'] ?? null) : ($stat['blocks'] ?? null);
$factor = $apparent ? 1 : 512;
if (!is_int($value) || $value < 0) {
coreutilsAddError($result, coreutilsError('du', 'size-unavailable',
"size metadata unavailable for '$name'" . ($apparent ? '' : '; use --apparent-size'), $name));
coreutilsAddError($result, coreutilsError(
'du',
'size-unavailable',
"size metadata unavailable for '$name'" . ($apparent ? '' : '; use --apparent-size'),
$name
));
return null;
}
if ($value > intdiv(PHP_INT_MAX, $factor)) {
Expand Down
8 changes: 6 additions & 2 deletions src/lib/searching.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,12 @@ function coreutilsGrepPaths(array $args, string $base, array $settings, array &$
}
if (isset($active[$identity])) {
// Keep cycle diagnostics separate from filesystem errors, as GNU grep does.
$result['data']['warnings'][] = coreutilsError('grep', 'directory-cycle',
"recursive directory loop at '" . $entry['name'] . "'", $entry['name']);
$result['data']['warnings'][] = coreutilsError(
'grep',
'directory-cycle',
"recursive directory loop at '" . $entry['name'] . "'",
$entry['name']
);
continue;
}
$children = coreutilsFsCall(fn () => scandir($path, SCANDIR_SORT_ASCENDING), $warning);
Expand Down
12 changes: 8 additions & 4 deletions tests/du.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,18 @@
file_put_contents($base . '/tree/file', 'small');
$file = lstat($base . '/tree/file');
$directory = lstat($base . '/tree');
skipUnless(isset($file['blocks'], $directory['blocks']) && $file['blocks'] >= 0 && $directory['blocks'] >= 0,
'allocated block metadata is unavailable');
skipUnless(
isset($file['blocks'], $directory['blocks']) && $file['blocks'] >= 0 && $directory['blocks'] >= 0,
'allocated block metadata is unavailable'
);
$result = du(parseCommand('du -ac tree'), $base);
same(0, $result['status']);
same($file['blocks'] * 512, $result['data']['entries'][0]['bytes']);
same(($file['blocks'] + $directory['blocks']) * 512, $result['data']['total']);
same((string) (intdiv($result['data']['total'], 1024) + ($result['data']['total'] % 1024 ? 1 : 0)) . "\ttotal\n",
substr(coreutilsText($result), strrpos(rtrim(coreutilsText($result)), "\n") + 1));
same(
(string) (intdiv($result['data']['total'], 1024) + ($result['data']['total'] % 1024 ? 1 : 0)) . "\ttotal\n",
substr(coreutilsText($result), strrpos(rtrim(coreutilsText($result)), "\n") + 1)
);
});

$tests['du sparse apparent size does not require reading contents'] = fn () => fixture(function ($base) {
Expand Down
Loading