mirror of
https://github.com/obsqrbtz/clrsync.git
synced 2026-04-08 20:19:04 +03:00
fix: do not copy whole dirs (doesnt work on nix-store)
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -10,6 +10,9 @@ out
|
||||
/AUR/pkg
|
||||
/AUR/src
|
||||
|
||||
/result
|
||||
/result-*
|
||||
|
||||
*.log
|
||||
*tar.zst
|
||||
*tar.gz
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <core/palette/color.hpp>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -56,25 +57,66 @@ std::filesystem::path config::get_data_dir()
|
||||
#endif
|
||||
}
|
||||
|
||||
void config::copy_file(const std::filesystem::path &src, const std::filesystem::path &dst)
|
||||
{
|
||||
if (std::filesystem::exists(dst))
|
||||
return;
|
||||
|
||||
std::ifstream in(src, std::ios::binary);
|
||||
std::ofstream out(dst, std::ios::binary);
|
||||
out << in.rdbuf();
|
||||
}
|
||||
|
||||
void config::copy_dir(const std::filesystem::path &src, const std::filesystem::path &dst)
|
||||
{
|
||||
for (auto const &entry : std::filesystem::recursive_directory_iterator(src))
|
||||
{
|
||||
auto rel = std::filesystem::relative(entry.path(), src);
|
||||
auto out = dst / rel;
|
||||
|
||||
if (entry.is_directory())
|
||||
{
|
||||
std::filesystem::create_directories(out);
|
||||
}
|
||||
else if (entry.is_regular_file())
|
||||
{
|
||||
copy_file(entry.path(), out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void config::copy_default_configs()
|
||||
{
|
||||
std::filesystem::path user_config = get_user_config_dir();
|
||||
std::filesystem::path default_dir = get_data_dir();
|
||||
std::filesystem::path user_dir = get_user_config_dir();
|
||||
std::filesystem::path system_dir = get_data_dir();
|
||||
|
||||
std::filesystem::create_directories(user_dir);
|
||||
|
||||
if (!std::filesystem::exists(user_config))
|
||||
{
|
||||
std::filesystem::create_directories(user_config);
|
||||
|
||||
std::filesystem::copy(default_dir / "config.toml", user_config / "config.toml");
|
||||
std::filesystem::copy(default_dir / "templates", user_config / "templates",
|
||||
std::filesystem::copy_options::recursive);
|
||||
std::filesystem::copy(default_dir / "palettes", user_config / "palettes",
|
||||
std::filesystem::copy_options::recursive);
|
||||
return;
|
||||
auto src = system_dir / "config.toml";
|
||||
auto dst = user_dir / "config.toml";
|
||||
if (!std::filesystem::exists(dst))
|
||||
copy_file(src, dst);
|
||||
}
|
||||
if (!std::filesystem::exists(user_config / "config.toml"))
|
||||
|
||||
{
|
||||
std::filesystem::copy(default_dir / "config.toml", user_config / "config.toml");
|
||||
auto src = system_dir / "templates";
|
||||
auto dst = user_dir / "templates";
|
||||
|
||||
if (!std::filesystem::exists(dst))
|
||||
std::filesystem::create_directories(dst);
|
||||
|
||||
copy_dir(src, dst);
|
||||
}
|
||||
|
||||
{
|
||||
auto src = system_dir / "palettes";
|
||||
auto dst = user_dir / "palettes";
|
||||
|
||||
if (!std::filesystem::exists(dst))
|
||||
std::filesystem::create_directories(dst);
|
||||
|
||||
copy_dir(src, dst);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@ class config
|
||||
std::string m_palettes_dir{};
|
||||
std::unique_ptr<io::file> m_file;
|
||||
std::unordered_map<std::string, theme_template> m_themes{};
|
||||
static void copy_file(const std::filesystem::path& src, const std::filesystem::path& dst);
|
||||
static void copy_dir(const std::filesystem::path& src, const std::filesystem::path& dst);
|
||||
void copy_default_configs();
|
||||
};
|
||||
} // namespace clrsync::core
|
||||
|
||||
Reference in New Issue
Block a user