FIX: add protection of empty HMS folder

jira: [none]
Change-Id: Ie963c58d525f8a40543104dcdb4f9ee3b188a03f
This commit is contained in:
xin.zhang 2025-01-08 14:48:26 +08:00 committed by lane.wei
parent d4354aa90e
commit 126d5a14ee
1 changed files with 29 additions and 11 deletions

View File

@ -123,22 +123,40 @@ int HMSQuery::download_hms_related(const std::string& hms_type, const std::strin
void HMSQuery::copy_from_data_dir_to_local() void HMSQuery::copy_from_data_dir_to_local()
{ {
const fs::path& from_dir = fs::path(Slic3r::resources_dir()) / HMS_PATH; const fs::path& from_dir = fs::path(Slic3r::resources_dir()) / HMS_PATH;
const fs::path& to_dir = fs::path(Slic3r::data_dir()) / HMS_PATH; if (!fs::exists(from_dir))
for (const auto& entry : fs::directory_iterator(from_dir))
{ {
const fs::path& source_path = entry.path(); assert(0);
const fs::path& relative_path = fs::relative(source_path, from_dir); return;
const fs::path& dest_path = to_dir / relative_path; }
if (fs::exists(dest_path))
{
continue;
}
if (fs::is_regular_file(source_path)) const fs::path& to_dir = fs::path(Slic3r::data_dir()) / HMS_PATH;
if (!fs::exists(to_dir))
{
fs::create_directory(to_dir);
}
try
{
for (const auto& entry : fs::directory_iterator(from_dir))
{ {
copy_file(source_path, dest_path); const fs::path& source_path = entry.path();
const fs::path& relative_path = fs::relative(source_path, from_dir);
const fs::path& dest_path = to_dir / relative_path;
if (fs::exists(dest_path))
{
continue;
}
if (fs::is_regular_file(source_path))
{
copy_file(source_path, dest_path);
}
} }
} }
catch (const std::exception&)
{
}
} }
int HMSQuery::load_from_local(const std::string& hms_type, const std::string& dev_id_type, json* load_json, std::string& load_version) int HMSQuery::load_from_local(const std::string& hms_type, const std::string& dev_id_type, json* load_json, std::string& load_version)