mirror of
https://github.com/laravel/valet.git
synced 2026-02-07 09:10:03 +01:00
Merge pull request #891 from drbyte/dnsmasq-gc
Cleanup old tld refs when switching tld or uninstalling
This commit is contained in:
@@ -2,12 +2,9 @@
|
|||||||
|
|
||||||
namespace Valet;
|
namespace Valet;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use Symfony\Component\Process\Process;
|
|
||||||
|
|
||||||
class DnsMasq
|
class DnsMasq
|
||||||
{
|
{
|
||||||
var $brew, $cli, $files;
|
var $brew, $cli, $files, $configuration;
|
||||||
|
|
||||||
var $dnsmasqMasterConfigFile = '/usr/local/etc/dnsmasq.conf';
|
var $dnsmasqMasterConfigFile = '/usr/local/etc/dnsmasq.conf';
|
||||||
var $dnsmasqSystemConfDir = '/usr/local/etc/dnsmasq.d';
|
var $dnsmasqSystemConfDir = '/usr/local/etc/dnsmasq.d';
|
||||||
@@ -15,17 +12,13 @@ class DnsMasq
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new DnsMasq instance.
|
* Create a new DnsMasq instance.
|
||||||
*
|
|
||||||
* @param Brew $brew
|
|
||||||
* @param CommandLine $cli
|
|
||||||
* @param Filesystem $files
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
function __construct(Brew $brew, CommandLine $cli, Filesystem $files)
|
function __construct(Brew $brew, CommandLine $cli, Filesystem $files, Configuration $configuration)
|
||||||
{
|
{
|
||||||
$this->cli = $cli;
|
$this->cli = $cli;
|
||||||
$this->brew = $brew;
|
$this->brew = $brew;
|
||||||
$this->files = $files;
|
$this->files = $files;
|
||||||
|
$this->configuration = $configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,6 +54,8 @@ function uninstall()
|
|||||||
$this->brew->stopService('dnsmasq');
|
$this->brew->stopService('dnsmasq');
|
||||||
$this->brew->uninstallFormula('dnsmasq');
|
$this->brew->uninstallFormula('dnsmasq');
|
||||||
$this->cli->run('rm -rf /usr/local/etc/dnsmasq.d/dnsmasq-valet.conf');
|
$this->cli->run('rm -rf /usr/local/etc/dnsmasq.d/dnsmasq-valet.conf');
|
||||||
|
$tld = $this->configuration->read()['tld'];
|
||||||
|
$this->files->unlink($this->resolverPath.'/'.$tld);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -145,6 +140,7 @@ function createTldResolver($tld)
|
|||||||
function updateTld($oldTld, $newTld)
|
function updateTld($oldTld, $newTld)
|
||||||
{
|
{
|
||||||
$this->files->unlink($this->resolverPath.'/'.$oldTld);
|
$this->files->unlink($this->resolverPath.'/'.$oldTld);
|
||||||
|
$this->files->unlink($this->dnsmasqUserConfigDir() . 'tld-' . $oldTld . '.conf');
|
||||||
|
|
||||||
$this->install($newTld);
|
$this->install($newTld);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
use Valet\DnsMasq;
|
use Valet\DnsMasq;
|
||||||
use Valet\Filesystem;
|
use Valet\Filesystem;
|
||||||
use Valet\CommandLine;
|
use Valet\CommandLine;
|
||||||
|
use Valet\Configuration;
|
||||||
use function Valet\user;
|
use function Valet\user;
|
||||||
use function Valet\resolve;
|
use function Valet\resolve;
|
||||||
use function Valet\swap;
|
use function Valet\swap;
|
||||||
@@ -60,7 +61,8 @@ public function test_update_tld_removes_old_resolver_and_reinstalls()
|
|||||||
{
|
{
|
||||||
$cli = Mockery::mock(CommandLine::class);
|
$cli = Mockery::mock(CommandLine::class);
|
||||||
$cli->shouldReceive('quietly')->with('rm /etc/resolver/old');
|
$cli->shouldReceive('quietly')->with('rm /etc/resolver/old');
|
||||||
$dnsMasq = Mockery::mock(DnsMasq::class.'[install]', [resolve(Brew::class), $cli, new Filesystem]);
|
swap(Configuration::class, $config = Mockery::spy(Configuration::class, ['read' => ['tld' => 'test']]));
|
||||||
|
$dnsMasq = Mockery::mock(DnsMasq::class.'[install]', [resolve(Brew::class), $cli, new Filesystem, $config]);
|
||||||
$dnsMasq->shouldReceive('install')->with('new');
|
$dnsMasq->shouldReceive('install')->with('new');
|
||||||
$dnsMasq->updateTld('old', 'new');
|
$dnsMasq->updateTld('old', 'new');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user