/
BsdFindAdapter.php
54 lines (48 loc) · 1.21 KB
/
BsdFindAdapter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Adapter;
use Symfony\Component\Finder\Shell\Shell;
use Symfony\Component\Finder\Shell\Command;
/**
* Shell engine implementation using BSD find command.
*
* @author Jean-François Simon <contact@jfsimon.fr>
*/
class BsdFindAdapter extends AbstractFindAdapter
{
/**
* {@inheritdoc}
*/
public function getName()
{
return 'bsd_find';
}
/**
* {@inheritdoc}
*/
protected function canBeUsed()
{
// FIXME: this adapter does not work yet with Shell::TYPE_DARWIN
return in_array($this->shell->getType(), array(Shell::TYPE_BSD)) && parent::canBeUsed();
}
/**
* {@inheritdoc}
*/
protected function buildFormatSorting(Command $command, $format)
{
$command
->get('find')
->add('-print0 | xargs -0 stat -f')
->arg($format.' %h/%f\\n')
->add('| sort | cut')
->arg('-d ')
->arg('-f2-');
}
}