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

fix: Correctly handle default configuration when user dirs do not exist #222

Merged
merged 1 commit into from
Aug 28, 2024
Merged
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
21 changes: 17 additions & 4 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ using namespace miracle;

namespace
{
const char* MIRACLE_USR_SHARE_DIR = "/usr/share/miracle-wm/config/default.yaml";
const char* MIRACLE_DEFAULT_CONFIG_FILE = "/usr/share/miracle-wm/config/default.yaml";
const char* MIRACLE_DEFAULT_CONFIG_DIR = "/usr/share/miracle-wm/default-config";

int program_exists(std::string const& name)
{
Expand Down Expand Up @@ -218,11 +219,23 @@ void FilesystemConfiguration::_init(std::optional<StartupApp> const& startup_app
mir::log_info("Configuration file path is: %s", config_path.c_str());
if (!std::filesystem::exists(config_path))
{
if (std::filesystem::exists(MIRACLE_USR_SHARE_DIR))

if (!std::filesystem::exists(std::filesystem::path(config_path).parent_path()))
{
mir::log_info("Configuration directory path missing, creating it now");
std::filesystem::create_directories(std::filesystem::path(config_path).parent_path());
}
if (std::filesystem::exists(MIRACLE_DEFAULT_CONFIG_DIR))
{
mir::log_info("Configuration hierarchy being copied from %s", MIRACLE_DEFAULT_CONFIG_DIR);
const auto fs_copyopts = std::filesystem::copy_options::recursive;
std::filesystem::copy(MIRACLE_DEFAULT_CONFIG_DIR, std::filesystem::path(config_path).parent_path(), fs_copyopts);
}
else if (std::filesystem::exists(MIRACLE_DEFAULT_CONFIG_FILE))
{
mir::log_info("Configuration being copied from %s", MIRACLE_USR_SHARE_DIR);
mir::log_info("Configuration being copied from %s", MIRACLE_DEFAULT_CONFIG_FILE);
std::filesystem::copy_file(
MIRACLE_USR_SHARE_DIR,
MIRACLE_DEFAULT_CONFIG_FILE,
config_path);
}
else
Expand Down
Loading