mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-13 20:16:01 +08:00
Added error-checking for child.wait() call during removable drive ejection (to prevent #5507)
Mark Ejection as failed if the wait() function fails. It seems that it is not simply possible to retrieve the exit code of the process in that case (although it usually finishes sucessfully).
This commit is contained in:
parent
6c399052c6
commit
99f5dfbde7
@ -277,14 +277,15 @@ void RemovableDriveManager::eject_drive()
|
|||||||
//std::cout<<"Ejecting "<<(*it).name<<" from "<< correct_path<<"\n";
|
//std::cout<<"Ejecting "<<(*it).name<<" from "<< correct_path<<"\n";
|
||||||
// there is no usable command in c++ so terminal command is used instead
|
// there is no usable command in c++ so terminal command is used instead
|
||||||
// but neither triggers "succesful safe removal messege"
|
// but neither triggers "succesful safe removal messege"
|
||||||
BOOST_LOG_TRIVIAL(info) << "Ejecting started";
|
|
||||||
boost::process::ipstream istd_err;
|
BOOST_LOG_TRIVIAL(info) << "Ejecting started";
|
||||||
boost::process::child child(
|
boost::process::ipstream istd_err;
|
||||||
|
boost::process::child child(
|
||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
boost::process::search_path("diskutil"), "eject", correct_path.c_str(), (boost::process::std_out & boost::process::std_err) > istd_err);
|
boost::process::search_path("diskutil"), "eject", correct_path.c_str(), (boost::process::std_out & boost::process::std_err) > istd_err);
|
||||||
//Another option how to eject at mac. Currently not working.
|
//Another option how to eject at mac. Currently not working.
|
||||||
//used insted of system() command;
|
//used insted of system() command;
|
||||||
//this->eject_device(correct_path);
|
//this->eject_device(correct_path);
|
||||||
#else
|
#else
|
||||||
boost::process::search_path("umount"), correct_path.c_str(), (boost::process::std_out & boost::process::std_err) > istd_err);
|
boost::process::search_path("umount"), correct_path.c_str(), (boost::process::std_out & boost::process::std_err) > istd_err);
|
||||||
#endif
|
#endif
|
||||||
@ -293,8 +294,19 @@ void RemovableDriveManager::eject_drive()
|
|||||||
BOOST_LOG_TRIVIAL(trace) << line;
|
BOOST_LOG_TRIVIAL(trace) << line;
|
||||||
}
|
}
|
||||||
// wait for command to finnish (blocks ui thread)
|
// wait for command to finnish (blocks ui thread)
|
||||||
child.wait();
|
std::error_code ec;
|
||||||
int err = child.exit_code();
|
child.wait(ec);
|
||||||
|
if (ec) {
|
||||||
|
// The wait call can fail, as it did in https://github.com/prusa3d/PrusaSlicer/issues/5507
|
||||||
|
// It can happen even in cases where the eject is sucessful, but better report it as failed.
|
||||||
|
// We did not find a way to reliably retrieve the exit code of the process.
|
||||||
|
BOOST_LOG_TRIVIAL(error) << "boost::process::child::wait() failed during Ejection. State of Ejection is unknown. Error code: " << ec.value();
|
||||||
|
assert(m_callback_evt_handler);
|
||||||
|
if (m_callback_evt_handler)
|
||||||
|
wxPostEvent(m_callback_evt_handler, RemovableDriveEjectEvent(EVT_REMOVABLE_DRIVE_EJECTED, std::pair<DriveData, bool>(*it_drive_data, false)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int err = child.exit_code();
|
||||||
if (err) {
|
if (err) {
|
||||||
BOOST_LOG_TRIVIAL(error) << "Ejecting failed. Exit code: " << err;
|
BOOST_LOG_TRIVIAL(error) << "Ejecting failed. Exit code: " << err;
|
||||||
assert(m_callback_evt_handler);
|
assert(m_callback_evt_handler);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user