1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-05 00:20:08 +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:
2022-03-29 19:38:30 +02:00
parent b406c0d4ee
commit a52355ec49
3 changed files with 18 additions and 3 deletions

View File

@@ -224,6 +224,20 @@ public function stopService($services)
// stop the sudo version
$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'");
}
}
}
}

View File

@@ -161,9 +161,7 @@ public function restart()
*/
public function stop()
{
info('Stopping nginx...');
$this->cli->quietly('sudo brew services stop '.$this->brew->nginxServiceName());
$this->brew->stopService(['nginx']);
}
/**

View File

@@ -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('quietly')->once()->with('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);
resolve(Brew::class)->stopService('dnsmasq');
}