debug log in copy_file_linux

This commit is contained in:
David Kocik 2021-06-11 11:46:19 +02:00
parent 7b506bc3cf
commit d6084621b2

View file

@ -443,6 +443,8 @@ 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;
@ -458,6 +460,8 @@ bool copy_file_linux(const boost::filesystem::path &from, const boost::filesyste
}
break;
}
BOOST_LOG_TRIVIAL(trace) << "infile.fd";
struct ::stat from_stat;
if (::fstat(infile.fd, &from_stat) != 0) {
@ -465,6 +469,8 @@ bool copy_file_linux(const boost::filesystem::path &from, const boost::filesyste
err = errno;
goto fail;
}
BOOST_LOG_TRIVIAL(trace) << "from_stat";
const mode_t from_mode = from_stat.st_mode;
if (!S_ISREG(from_mode)) {
@ -472,6 +478,8 @@ bool copy_file_linux(const boost::filesystem::path &from, const boost::filesyste
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;
@ -487,22 +495,29 @@ bool copy_file_linux(const boost::filesystem::path &from, const boost::filesyste
}
break;
}
BOOST_LOG_TRIVIAL(trace) << "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
@ -530,6 +545,8 @@ bool copy_file_linux(const boost::filesystem::path &from, const boost::filesyste
}
}
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) {
@ -553,6 +570,8 @@ 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__