From 4146f1a62e2609cf972c9b5fb00c275a80f24bf3 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Tue, 15 Jun 2021 16:12:55 +0200 Subject: [PATCH] fix of #6588 - using same copy function for updating presets as for exporting gcode --- src/libslic3r/utils.cpp | 22 ---------------------- src/slic3r/Utils/PresetUpdater.cpp | 15 +++++++-------- 2 files changed, 7 insertions(+), 30 deletions(-) diff --git a/src/libslic3r/utils.cpp b/src/libslic3r/utils.cpp index d4b65da2f..1f3079fba 100644 --- a/src/libslic3r/utils.cpp +++ b/src/libslic3r/utils.cpp @@ -490,8 +490,6 @@ bool copy_file_linux(const boost::filesystem::path &from, const boost::filesyste ec.clear(); int err = 0; - BOOST_LOG_TRIVIAL(trace) << "copy_file_linux("<(max_send_size)) size_to_copy = static_cast(size_left); - BOOST_LOG_TRIVIAL(trace) << "sendfile " << outfile.fd << "; " << infile.fd << "; " << size_to_copy; ssize_t sz = ::sendfile(outfile.fd, infile.fd, nullptr, size_to_copy); - BOOST_LOG_TRIVIAL(trace) << sz; if (sz < 0) { err = errno; if (offset == 0u) { @@ -606,9 +589,6 @@ bool copy_file_linux(const boost::filesystem::path &from, const boost::filesyste offset += sz; } } - - BOOST_LOG_TRIVIAL(trace) << "sendfile loop"; - // If we created a new file with an explicitly added S_IWUSR permission, // we may need to update its mode bits to match the source file. if (to_mode != from_mode && ::fchmod(outfile.fd, from_mode) != 0) { @@ -632,8 +612,6 @@ bool copy_file_linux(const boost::filesystem::path &from, const boost::filesyste if (err != 0) goto fail_errno; - BOOST_LOG_TRIVIAL(trace) << "copy_file_linux success"; - return true; } #endif // __linux__ diff --git a/src/slic3r/Utils/PresetUpdater.cpp b/src/slic3r/Utils/PresetUpdater.cpp index 60dfe05c7..c65ec31d3 100644 --- a/src/slic3r/Utils/PresetUpdater.cpp +++ b/src/slic3r/Utils/PresetUpdater.cpp @@ -56,16 +56,15 @@ static const char *TMP_EXTENSION = ".download"; void copy_file_fix(const fs::path &source, const fs::path &target) { - 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 - if (fs::exists(target)) { - fs::permissions(target, perms); + std::string error_message; + CopyFileResult cfr = copy_file(source.string(), target.string(), error_message, false); + if (cfr != CopyFileResult::SUCCESS) { + BOOST_LOG_TRIVIAL(error) << "Copying failed(" << cfr << "): " << error_message; + throw Slic3r::CriticalException(GUI::format( + _L("Copying of file %1% to %2% failed: %3%"), + source, target, error_message)); } - fs::copy_file(source, target, fs::copy_option::overwrite_if_exists); - fs::permissions(target, perms); } struct Update