mirror of
https://github.com/laravel/valet.git
synced 2026-02-05 16:40:05 +01:00
Restore original directory permissions
As discussed in #1220, cleaning up after stopping Homebrew services that run as root is probably the best solution for now. What's changed: - Stopping any Homebrew service now restores the appropriate permissions for the Homebrew directories - Stopping nginx now also happens via $this->brew (to avoid code duplication) The tests were updated to reflect this change.
This commit is contained in:
@@ -224,6 +224,20 @@ public function stopService($services)
|
|||||||
|
|
||||||
// stop the sudo version
|
// stop the sudo version
|
||||||
$this->cli->quietly('sudo brew services stop '.$service);
|
$this->cli->quietly('sudo brew services stop '.$service);
|
||||||
|
|
||||||
|
// restore folder permissions: for each brew formula, these directories are owned by root:admin
|
||||||
|
$directories = [
|
||||||
|
BREW_PREFIX . "/Cellar/$service",
|
||||||
|
BREW_PREFIX . "/opt/$service",
|
||||||
|
BREW_PREFIX . "/var/homebrew/linked/$service",
|
||||||
|
];
|
||||||
|
|
||||||
|
// if the services aren't running: we'll restore the original permissions
|
||||||
|
$whoami = get_current_user();
|
||||||
|
|
||||||
|
foreach ($directories as $directory) {
|
||||||
|
$this->cli->quietly("sudo chown -R {$whoami}:admin '$directory'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,9 +161,7 @@ public function restart()
|
|||||||
*/
|
*/
|
||||||
public function stop()
|
public function stop()
|
||||||
{
|
{
|
||||||
info('Stopping nginx...');
|
$this->brew->stopService(['nginx']);
|
||||||
|
|
||||||
$this->cli->quietly('sudo brew services stop '.$this->brew->nginxServiceName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -122,6 +122,9 @@ public function test_stop_stops_the_service_using_homebrew_services()
|
|||||||
$cli->shouldReceive('runAsUser')->once()->with('brew info dnsmasq --json')->andReturn('[{"name":"dnsmasq","full_name":"dnsmasq","aliases":[],"versioned_formulae":[],"versions":{"stable":"1"},"installed":[{"version":"1"}]}]');
|
$cli->shouldReceive('runAsUser')->once()->with('brew info dnsmasq --json')->andReturn('[{"name":"dnsmasq","full_name":"dnsmasq","aliases":[],"versioned_formulae":[],"versions":{"stable":"1"},"installed":[{"version":"1"}]}]');
|
||||||
$cli->shouldReceive('quietly')->once()->with('brew services stop dnsmasq');
|
$cli->shouldReceive('quietly')->once()->with('brew services stop dnsmasq');
|
||||||
$cli->shouldReceive('quietly')->once()->with('sudo brew services stop dnsmasq');
|
$cli->shouldReceive('quietly')->once()->with('sudo brew services stop dnsmasq');
|
||||||
|
$cli->shouldReceive('quietly')->once()->with("sudo chown -R ".user().":admin '".BREW_PREFIX."/Cellar/dnsmasq'");
|
||||||
|
$cli->shouldReceive('quietly')->once()->with("sudo chown -R ".user().":admin '".BREW_PREFIX."/opt/dnsmasq'");
|
||||||
|
$cli->shouldReceive('quietly')->once()->with("sudo chown -R ".user().":admin '".BREW_PREFIX."/var/homebrew/linked/dnsmasq'");
|
||||||
swap(CommandLine::class, $cli);
|
swap(CommandLine::class, $cli);
|
||||||
resolve(Brew::class)->stopService('dnsmasq');
|
resolve(Brew::class)->stopService('dnsmasq');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user