From 2d6452acb5f127808a8198415ee0a9e24b232b6a Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 3 Mar 2021 13:04:44 -0800 Subject: [PATCH] In Arcanist, when trying to write to a file configuration source, create missing directories Summary: The ".git/arc" directory may need to be created when writing to working copy configuration. Test Plan: - Tried to store an answer to a prompt in a new working copy. - Before: error that ".git/arc" does not exist. - After: prompt saved to working copy configuration. Differential Revision: https://secure.phabricator.com/D21588 --- .../ArcanistFilesystemConfigurationSource.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/config/source/ArcanistFilesystemConfigurationSource.php b/src/config/source/ArcanistFilesystemConfigurationSource.php index ffcb5016..4281c830 100644 --- a/src/config/source/ArcanistFilesystemConfigurationSource.php +++ b/src/config/source/ArcanistFilesystemConfigurationSource.php @@ -39,7 +39,20 @@ abstract class ArcanistFilesystemConfigurationSource $content = id(new PhutilJSON()) ->encodeFormatted($values); - Filesystem::writeFile($this->path, $content); + $path = $this->path; + + // If the containing directory does not exist yet, create it. + // + // This is expected when (for example) you first write to project + // configuration in a Git working copy: the ".git/arc" directory will + // not exist yet. + + $dir = dirname($path); + if (!Filesystem::pathExists($dir)) { + Filesystem::createDirectory($dir, 0755, $recursive = true); + } + + Filesystem::writeFile($path, $content); } }