Improved exception throwing at copy file in preset updater
This commit is contained in:
parent
740ffc03b4
commit
03028bb23e
@ -54,18 +54,28 @@ static const char *INDEX_FILENAME = "index.idx";
|
||||
static const char *TMP_EXTENSION = ".download";
|
||||
|
||||
|
||||
void copy_file_fix(const fs::path &source, const fs::path &target)
|
||||
//void copy_file_fix(const fs::path &source, const fs::path &target)
|
||||
void copy_file_fix(const fs::path& source, const fs::path& target,const std::string& caller_function_name)
|
||||
{
|
||||
static const auto perms = fs::owner_read | fs::owner_write | fs::group_read | fs::others_read; // aka 644
|
||||
|
||||
BOOST_LOG_TRIVIAL(debug) << format("PresetUpdater: Copying %1% -> %2%", source, target);
|
||||
|
||||
// Make sure the file has correct permission both before and after we copy over it
|
||||
boost::system::error_code ec;
|
||||
if (fs::exists(target)) {
|
||||
fs::permissions(target, perms);
|
||||
fs::permissions(target, perms, ec);
|
||||
if(ec)
|
||||
throw Slic3r::CriticalException((boost::format(_utf8(L("Copying of file %1% to %2% failed. Permissions fail at target file before copying.\nError message : %3%\n This error happend during %4% phase."))) % source % target % ec.message() % caller_function_name).str());
|
||||
}
|
||||
fs::copy_file(source, target, fs::copy_option::overwrite_if_exists);
|
||||
fs::permissions(target, perms);
|
||||
ec.clear();
|
||||
fs::copy_file(source, target, fs::copy_option::overwrite_if_exists, ec);
|
||||
if (ec)
|
||||
throw Slic3r::CriticalException((boost::format(_utf8(L("Copying of file %1% to %2% failed.\nError message : %3%\n Copying was triggered by function: %4%"))) % source % target % ec.message() % caller_function_name).str());
|
||||
ec.clear();
|
||||
fs::permissions(target, perms, ec);
|
||||
if (ec)
|
||||
throw Slic3r::CriticalException((boost::format(_utf8(L("Copying of file %1% to %2% failed. Permissions fail at target file after copying.\nError message : %3%\n Copying was triggered by function: %4%"))) % source % target % ec.message() % caller_function_name).str());
|
||||
}
|
||||
|
||||
struct Update
|
||||
@ -91,7 +101,9 @@ struct Update
|
||||
|
||||
void install() const
|
||||
{
|
||||
copy_file_fix(source, target);
|
||||
std::string error_message;
|
||||
copy_file_fix(source, target, _utf8(L("install")));
|
||||
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const Update &self)
|
||||
@ -382,7 +394,7 @@ void PresetUpdater::priv::check_install_indices() const
|
||||
|
||||
if (! fs::exists(path_in_cache)) {
|
||||
BOOST_LOG_TRIVIAL(info) << "Install index from resources: " << path.filename();
|
||||
copy_file_fix(path, path_in_cache);
|
||||
copy_file_fix(path, path_in_cache, _utf8(L("checking install indices")));
|
||||
} else {
|
||||
Index idx_rsrc, idx_cache;
|
||||
idx_rsrc.load(path);
|
||||
@ -390,7 +402,7 @@ void PresetUpdater::priv::check_install_indices() const
|
||||
|
||||
if (idx_cache.version() < idx_rsrc.version()) {
|
||||
BOOST_LOG_TRIVIAL(info) << "Update index from resources: " << path.filename();
|
||||
copy_file_fix(path, path_in_cache);
|
||||
copy_file_fix(path, path_in_cache, _utf8(L("checking install indices")));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -570,7 +582,7 @@ Updates PresetUpdater::priv::get_config_updates(const Semver &old_slic3r_version
|
||||
updates.updates.emplace_back(std::move(new_update));
|
||||
// 'Install' the index in the vendor directory. This is used to memoize
|
||||
// offered updates and to not offer the same update again if it was cancelled by the user.
|
||||
copy_file_fix(bundle_path_idx_to_install, bundle_path_idx);
|
||||
copy_file_fix(bundle_path_idx_to_install, bundle_path_idx, _utf8(L("getting config updates")));
|
||||
} else {
|
||||
BOOST_LOG_TRIVIAL(warning) << format("Index for vendor %1% indicates update (%2%) but the new bundle was found neither in cache nor resources",
|
||||
idx.vendor(),
|
||||
|
Loading…
Reference in New Issue
Block a user