fix of #6588 - using same copy function for updating presets as for exporting gcode
This commit is contained in:
parent
f60f08fc64
commit
4146f1a62e
2 changed files with 7 additions and 30 deletions
|
@ -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("<<from<<", "<<to<< ")";
|
||||
|
||||
// Note: Declare fd_wrappers here so that errno is not clobbered by close() that may be called in fd_wrapper destructors
|
||||
fd_wrapper infile, outfile;
|
||||
|
||||
|
@ -507,8 +505,6 @@ bool copy_file_linux(const boost::filesystem::path &from, const boost::filesyste
|
|||
}
|
||||
break;
|
||||
}
|
||||
BOOST_LOG_TRIVIAL(trace) << "infile.fd " << infile.fd;
|
||||
|
||||
|
||||
struct ::stat from_stat;
|
||||
if (::fstat(infile.fd, &from_stat) != 0) {
|
||||
|
@ -517,16 +513,12 @@ bool copy_file_linux(const boost::filesystem::path &from, const boost::filesyste
|
|||
goto fail;
|
||||
}
|
||||
|
||||
BOOST_LOG_TRIVIAL(trace) << "from_stat";
|
||||
|
||||
const mode_t from_mode = from_stat.st_mode;
|
||||
if (!S_ISREG(from_mode)) {
|
||||
err = ENOSYS;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
BOOST_LOG_TRIVIAL(trace) << "from_mode";
|
||||
|
||||
// Enable writing for the newly created files. Having write permission set is important e.g. for NFS,
|
||||
// which checks the file permission on the server, even if the client's file descriptor supports writing.
|
||||
mode_t to_mode = from_mode | S_IWUSR;
|
||||
|
@ -542,29 +534,22 @@ bool copy_file_linux(const boost::filesystem::path &from, const boost::filesyste
|
|||
}
|
||||
break;
|
||||
}
|
||||
BOOST_LOG_TRIVIAL(trace) << "outfile.fd " << outfile.fd;
|
||||
|
||||
struct ::stat to_stat;
|
||||
if (::fstat(outfile.fd, &to_stat) != 0)
|
||||
goto fail_errno;
|
||||
|
||||
BOOST_LOG_TRIVIAL(trace) << "to_stat";
|
||||
|
||||
to_mode = to_stat.st_mode;
|
||||
if (!S_ISREG(to_mode)) {
|
||||
err = ENOSYS;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
BOOST_LOG_TRIVIAL(trace) << "to_mode";
|
||||
|
||||
if (from_stat.st_dev == to_stat.st_dev && from_stat.st_ino == to_stat.st_ino) {
|
||||
err = EEXIST;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
BOOST_LOG_TRIVIAL(trace) << "from / to compare";
|
||||
|
||||
//! copy_file implementation that uses sendfile loop. Requires sendfile to support file descriptors.
|
||||
//FIXME Vojtech: This is a copy loop valid for Linux 2.6.33 and newer.
|
||||
// copy_file_data_copy_file_range() supports cross-filesystem copying since 5.3, but Vojtech did not want to polute this
|
||||
|
@ -579,9 +564,7 @@ bool copy_file_linux(const boost::filesystem::path &from, const boost::filesyste
|
|||
std::size_t size_to_copy = max_send_size;
|
||||
if (size_left < static_cast<uintmax_t>(max_send_size))
|
||||
size_to_copy = static_cast<std::size_t>(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__
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue