Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve detection of home path. Also allow ~/.grav on Windows, drop ConsoleTrait::isWindows() method, used just for that. #1204

Merged
merged 6 commits into from
Dec 16, 2016
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# v1.1.10
## XX/XX/2016

1. [](#improved)
* Improve detection of home path. Also allow ~/.grav on Windows, drop ConsoleTrait::isWindows() method, used only for that [#1204](https://github.com/getgrav/grav/pull/1204)
1. [](#bugfix)
* Fixed case where extracting a package would cause an error during rename
* Fix issue with using Yaml::parse direcly on a filename, now deprecated

# v1.1.9
## 12/13/2016
Expand Down
13 changes: 4 additions & 9 deletions system/src/Grav/Console/Cli/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,15 @@ protected function serve()
// fix trailing slash
$this->destination = rtrim($this->destination, DS) . DS;
$this->user_path = $this->destination . USER_PATH;

if (false === $this->isWindows()) {
$local_config_file = exec('eval echo ~/.grav/config');
if (file_exists($local_config_file)) {
$this->local_config = Yaml::parse($local_config_file);
$this->output->writeln('Read local config from <cyan>' . $local_config_file . '</cyan>');
}
if ($local_config_file = $this->loadLocalConfig()) {
$this->output->writeln('Read local config from <cyan>' . $local_config_file . '</cyan>');
}

// Look for dependencies file in ROOT and USER dir
if (file_exists($this->user_path . $dependencies_file)) {
$this->config = Yaml::parse($this->user_path . $dependencies_file);
$this->config = Yaml::parse(file_get_contents($this->user_path . $dependencies_file));
} elseif (file_exists($this->destination . $dependencies_file)) {
$this->config = Yaml::parse($this->destination . $dependencies_file);
$this->config = Yaml::parse(file_get_contents($this->destination . $dependencies_file));
} else {
$this->output->writeln('<red>ERROR</red> Missing .dependencies file in <cyan>user/</cyan> folder');
}
Expand Down
24 changes: 13 additions & 11 deletions system/src/Grav/Console/ConsoleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Yaml;

trait ConsoleTrait
{
Expand Down Expand Up @@ -113,19 +114,20 @@ public function clearCache($all = [])
}

/**
* Validate if the system is based on windows or not.
* Load the local config file
*
* @return bool
* @return mixed string the local config file name. false if local config does not exist
*/
public function isWindows()
public function loadLocalConfig()
{
$keys = [
'CYGWIN_NT-5.1',
'WIN32',
'WINNT',
'Windows'
];

return array_key_exists(PHP_OS, $keys);
$home_folder = getenv('HOME') ?: getenv('HOMEDRIVE') . getenv('HOMEPATH');
$local_config_file = $home_folder . '/.grav/config';

if (file_exists($local_config_file)) {
$this->local_config = Yaml::parse(file_get_contents($local_config_file));
return $local_config_file;
}

return false;
}
}
9 changes: 1 addition & 8 deletions system/src/Grav/Console/Gpm/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Yaml\Yaml;

define('GIT_REGEX', '/http[s]?:\/\/(?:.*@)?(github|bitbucket)(?:.org|.com)\/.*\/(.*)/');

Expand Down Expand Up @@ -112,13 +111,7 @@ protected function serve()

$packages = array_map('strtolower', $this->input->getArgument('package'));
$this->data = $this->gpm->findPackages($packages);

if (false === $this->isWindows() && @is_file(getenv("HOME") . '/.grav/config')) {
$local_config_file = exec('eval echo ~/.grav/config');
if (file_exists($local_config_file)) {
$this->local_config = Yaml::parse($local_config_file);
}
}
$this->loadLocalConfig();

if (
!Installer::isGravInstance($this->destination) ||
Expand Down