Changeset View
Changeset View
Standalone View
Standalone View
src/configuration/ArcanistConfigurationManager.php
| Show First 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | if ($this->userConfigCache === null) { | ||||
| if (!$mode) { | if (!$mode) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Unable to read file permissions for "%s"!', | 'Unable to read file permissions for "%s"!', | ||||
| $user_config_path)); | $user_config_path)); | ||||
| } | } | ||||
| if ($mode & 0177) { | if ($mode & 0177) { | ||||
| // Mode should allow only owner access. | // Mode should allow only owner access. | ||||
| $prompt = "File permissions on your ~/.arcrc are too open. ". | $prompt = pht( | ||||
| "Fix them by chmod'ing to 600?"; | "File permissions on your %s are too open. ". | ||||
| "Fix them by chmod'ing to 600?", | |||||
| '~/.arcrc'); | |||||
| if (!phutil_console_confirm($prompt, $default_no = false)) { | if (!phutil_console_confirm($prompt, $default_no = false)) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| 'Set ~/.arcrc to file mode 600.'); | pht('Set %s to file mode 600.', '~/.arcrc')); | ||||
| } | } | ||||
| execx('chmod 600 %s', $user_config_path); | execx('chmod 600 %s', $user_config_path); | ||||
| // Drop the stat cache so we don't read the old permissions if | // Drop the stat cache so we don't read the old permissions if | ||||
| // we end up here again. If we don't do this, we may prompt the user | // we end up here again. If we don't do this, we may prompt the user | ||||
| // to fix permissions multiple times. | // to fix permissions multiple times. | ||||
| clearstatcache(); | clearstatcache(); | ||||
| } | } | ||||
| } | } | ||||
| $user_config_data = Filesystem::readFile($user_config_path); | $user_config_data = Filesystem::readFile($user_config_path); | ||||
| try { | try { | ||||
| $user_config = phutil_json_decode($user_config_data); | $user_config = phutil_json_decode($user_config_data); | ||||
| } catch (PhutilJSONParserException $ex) { | } catch (PhutilJSONParserException $ex) { | ||||
| throw new PhutilProxyException( | throw new PhutilProxyException( | ||||
| "Your '~/.arcrc' file is not a valid JSON file.", | pht("Your '%s' file is not a valid JSON file.", '~/.arcrc'), | ||||
| $ex); | $ex); | ||||
| } | } | ||||
| } else { | } else { | ||||
| $console->writeLog( | $console->writeLog( | ||||
| "%s\n", | "%s\n", | ||||
| pht( | pht( | ||||
| 'Config: Did not find user configuration at "%s".', | 'Config: Did not find user configuration at "%s".', | ||||
| $user_config_path)); | $user_config_path)); | ||||
| Show All 19 Lines | public function writeUserConfigurationFile($config) { | ||||
| if (!phutil_is_windows()) { | if (!phutil_is_windows()) { | ||||
| execx('chmod 600 %s', $path); | execx('chmod 600 %s', $path); | ||||
| } | } | ||||
| } | } | ||||
| public function setUserConfigurationFileLocation($custom_arcrc) { | public function setUserConfigurationFileLocation($custom_arcrc) { | ||||
| if (!Filesystem::pathExists($custom_arcrc)) { | if (!Filesystem::pathExists($custom_arcrc)) { | ||||
| throw new Exception( | throw new Exception( | ||||
| 'Custom arcrc file was specified, but it was not found!'); | pht('Custom %s file was specified, but it was not found!', 'arcrc')); | ||||
| } | } | ||||
| $this->customArcrcFilename = $custom_arcrc; | $this->customArcrcFilename = $custom_arcrc; | ||||
| $this->userConfigCache = null; | $this->userConfigCache = null; | ||||
| } | } | ||||
| public function getUserConfigurationFileLocation() { | public function getUserConfigurationFileLocation() { | ||||
| if (strlen($this->customArcrcFilename)) { | if (strlen($this->customArcrcFilename)) { | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | /* -( Read/write config )--------------------------------------------------- */ | ||||
| public function applyRuntimeArcConfig($args) { | public function applyRuntimeArcConfig($args) { | ||||
| $arcanist_settings = new ArcanistSettings(); | $arcanist_settings = new ArcanistSettings(); | ||||
| $options = $args->getArg('config'); | $options = $args->getArg('config'); | ||||
| foreach ($options as $opt) { | foreach ($options as $opt) { | ||||
| $opt_config = preg_split('/=/', $opt, 2); | $opt_config = preg_split('/=/', $opt, 2); | ||||
| if (count($opt_config) !== 2) { | if (count($opt_config) !== 2) { | ||||
| throw new ArcanistUsageException("Argument was '{$opt}', but must be ". | throw new ArcanistUsageException( | ||||
| "'name=value'. For example, history.immutable=true"); | pht( | ||||
| "Argument was '%s', but must be '%s'. For example, %s", | |||||
| $opt, | |||||
| 'name=value', | |||||
| 'history.immutable=true')); | |||||
| } | } | ||||
| list($key, $value) = $opt_config; | list($key, $value) = $opt_config; | ||||
| $value = $arcanist_settings->willWriteValue($key, $value); | $value = $arcanist_settings->willWriteValue($key, $value); | ||||
| $this->setRuntimeConfig($key, $value); | $this->setRuntimeConfig($key, $value); | ||||
| } | } | ||||
| return $this->runtimeConfig; | return $this->runtimeConfig; | ||||
| } | } | ||||
| public function readDefaultConfig() { | public function readDefaultConfig() { | ||||
| $settings = new ArcanistSettings(); | $settings = new ArcanistSettings(); | ||||
| return $settings->getDefaultSettings(); | return $settings->getDefaultSettings(); | ||||
| } | } | ||||
| } | } | ||||