mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-14 20:45:54 +08:00
fix of #6588 - using same copy function for updating presets as for exporting gcode
This commit is contained in:
parent
f60f08fc64
commit
4146f1a62e
@ -490,8 +490,6 @@ bool copy_file_linux(const boost::filesystem::path &from, const boost::filesyste
|
|||||||
ec.clear();
|
ec.clear();
|
||||||
int err = 0;
|
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
|
// 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;
|
fd_wrapper infile, outfile;
|
||||||
|
|
||||||
@ -507,8 +505,6 @@ bool copy_file_linux(const boost::filesystem::path &from, const boost::filesyste
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
BOOST_LOG_TRIVIAL(trace) << "infile.fd " << infile.fd;
|
|
||||||
|
|
||||||
|
|
||||||
struct ::stat from_stat;
|
struct ::stat from_stat;
|
||||||
if (::fstat(infile.fd, &from_stat) != 0) {
|
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;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(trace) << "from_stat";
|
|
||||||
|
|
||||||
const mode_t from_mode = from_stat.st_mode;
|
const mode_t from_mode = from_stat.st_mode;
|
||||||
if (!S_ISREG(from_mode)) {
|
if (!S_ISREG(from_mode)) {
|
||||||
err = ENOSYS;
|
err = ENOSYS;
|
||||||
goto fail;
|
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,
|
// 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.
|
// 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;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
BOOST_LOG_TRIVIAL(trace) << "outfile.fd " << outfile.fd;
|
|
||||||
|
|
||||||
struct ::stat to_stat;
|
struct ::stat to_stat;
|
||||||
if (::fstat(outfile.fd, &to_stat) != 0)
|
if (::fstat(outfile.fd, &to_stat) != 0)
|
||||||
goto fail_errno;
|
goto fail_errno;
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(trace) << "to_stat";
|
|
||||||
|
|
||||||
to_mode = to_stat.st_mode;
|
to_mode = to_stat.st_mode;
|
||||||
if (!S_ISREG(to_mode)) {
|
if (!S_ISREG(to_mode)) {
|
||||||
err = ENOSYS;
|
err = ENOSYS;
|
||||||
goto fail;
|
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) {
|
if (from_stat.st_dev == to_stat.st_dev && from_stat.st_ino == to_stat.st_ino) {
|
||||||
err = EEXIST;
|
err = EEXIST;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(trace) << "from / to compare";
|
|
||||||
|
|
||||||
//! copy_file implementation that uses sendfile loop. Requires sendfile to support file descriptors.
|
//! 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.
|
//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
|
// 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;
|
std::size_t size_to_copy = max_send_size;
|
||||||
if (size_left < static_cast<uintmax_t>(max_send_size))
|
if (size_left < static_cast<uintmax_t>(max_send_size))
|
||||||
size_to_copy = static_cast<std::size_t>(size_left);
|
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);
|
ssize_t sz = ::sendfile(outfile.fd, infile.fd, nullptr, size_to_copy);
|
||||||
BOOST_LOG_TRIVIAL(trace) << sz;
|
|
||||||
if (sz < 0) {
|
if (sz < 0) {
|
||||||
err = errno;
|
err = errno;
|
||||||
if (offset == 0u) {
|
if (offset == 0u) {
|
||||||
@ -606,9 +589,6 @@ bool copy_file_linux(const boost::filesystem::path &from, const boost::filesyste
|
|||||||
offset += sz;
|
offset += sz;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(trace) << "sendfile loop";
|
|
||||||
|
|
||||||
// If we created a new file with an explicitly added S_IWUSR permission,
|
// 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.
|
// we may need to update its mode bits to match the source file.
|
||||||
if (to_mode != from_mode && ::fchmod(outfile.fd, from_mode) != 0) {
|
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)
|
if (err != 0)
|
||||||
goto fail_errno;
|
goto fail_errno;
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(trace) << "copy_file_linux success";
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif // __linux__
|
#endif // __linux__
|
||||||
|
@ -56,16 +56,15 @@ 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)
|
||||||
{
|
{
|
||||||
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);
|
BOOST_LOG_TRIVIAL(debug) << format("PresetUpdater: Copying %1% -> %2%", source, target);
|
||||||
|
std::string error_message;
|
||||||
// Make sure the file has correct permission both before and after we copy over it
|
CopyFileResult cfr = copy_file(source.string(), target.string(), error_message, false);
|
||||||
if (fs::exists(target)) {
|
if (cfr != CopyFileResult::SUCCESS) {
|
||||||
fs::permissions(target, perms);
|
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
|
struct Update
|
||||||
|
Loading…
x
Reference in New Issue
Block a user