@@ -1081,6 +1081,24 @@ void saveImage(image::Image<image::RGBAfColor>& image,
10811081 }
10821082}
10831083
1084+ bool isFileReadable (const std::string& filename)
1085+ {
1086+ if (!fs::exists (filename))
1087+ {
1088+ return false ;
1089+ }
1090+ if (!fs::is_regular_file (filename))
1091+ {
1092+ return false ;
1093+ }
1094+ std::ifstream file (filename, std::ios::binary);
1095+ if (!file.is_open ())
1096+ {
1097+ return false ;
1098+ }
1099+ return true ;
1100+ }
1101+
10841102int aliceVision_main (int argc, char * argv[])
10851103{
10861104 std::string inputExpression;
@@ -1653,11 +1671,18 @@ int aliceVision_main(int argc, char* argv[])
16531671 sfmfilePath += " _0" ;
16541672 }
16551673 sfmfilePath += (fs::path (inputExpression).extension ()).generic_string ();
1656- if (!sfmDataIO::save (sfmData, sfmfilePath, sfmDataIO::ESfMData (sfmDataIO::ALL)))
1674+ std::string sfmTempfilePath = (fs::path (outputPath) / fs::path (inputExpression).stem ()).generic_string ();
1675+ if (rangeBlocksCount > 1 )
1676+ {
1677+ sfmTempfilePath += " _0_tmp" ;
1678+ }
1679+ sfmTempfilePath += (fs::path (inputExpression).extension ()).generic_string ();
1680+ if (!sfmDataIO::save (sfmData, sfmTempfilePath, sfmDataIO::ESfMData (sfmDataIO::ALL)))
16571681 {
16581682 ALICEVISION_LOG_ERROR (" The output SfMData file '" << sfmfilePath << " ' cannot be written." );
16591683 return EXIT_FAILURE;
16601684 }
1685+ fs::rename (sfmTempfilePath, sfmfilePath);
16611686 }
16621687 else
16631688 {
@@ -1671,22 +1696,29 @@ int aliceVision_main(int argc, char* argv[])
16711696 std::chrono::seconds interval = std::chrono::seconds (1 );
16721697 std::chrono::seconds timeout = std::chrono::seconds (rangeIteration*60 );
16731698 auto start_time = std::chrono::steady_clock::now ();
1674- while (!sfmDataIO::load (sfmDataNew, sfmfilePath_in, sfmDataIO::ALL))
1699+ std::chrono::seconds durationSeconds; // = std::chrono::duration_cast<std::chrono::seconds>(start_time);
1700+ while (!isFileReadable (sfmfilePath_in))
16751701 {
16761702 auto elapsed = std::chrono::steady_clock::now () - start_time;
1677- if (elapsed > timeout || fs::is_exist (timeoutFilePath))
1703+ durationSeconds = std::chrono::duration_cast<std::chrono::seconds>(elapsed);
1704+ if (elapsed > timeout || fs::exists (timeoutFilePath))
16781705 {
1679- if (!fs::is_exist (timeoutFilePath))
1706+ if (!fs::exists (timeoutFilePath))
16801707 {
16811708 std::ofstream timeoutFile (timeoutFilePath);
1682- timeoutFile.close ()
1709+ timeoutFile.close ();
16831710 }
1684- auto durationSeconds = std::chrono::duration_cast<std::chrono::seconds>(elapsed);
16851711 ALICEVISION_LOG_ERROR (" Timeout reached waiting the SfMData file '" << sfmfilePath_in << " ' after " << durationSeconds.count () << " s." );
16861712 return EXIT_FAILURE;
16871713 }
16881714 std::this_thread::sleep_for (interval);
16891715 }
1716+ ALICEVISION_LOG_INFO (" Temporary SfMData file '" << sfmfilePath_in << " ' available after " << durationSeconds.count () << " s." );
1717+ if (!sfmDataIO::load (sfmDataNew, sfmfilePath_in, sfmDataIO::ALL))
1718+ {
1719+ ALICEVISION_LOG_ERROR (" Temporary SfMData file '" << sfmfilePath_in << " ' cannot be opened" );
1720+ return EXIT_FAILURE;
1721+ }
16901722
16911723 for (auto & viewId : updatedViews)
16921724 {
@@ -1699,12 +1731,23 @@ int aliceVision_main(int argc, char* argv[])
16991731 sfmfilePath += " _" + std::to_string (rangeIteration);
17001732 }
17011733 sfmfilePath += (fs::path (inputExpression).extension ()).generic_string ();
1702- if (!sfmDataIO::save (sfmDataNew, sfmfilePath, sfmDataIO::ESfMData (sfmDataIO::ALL)))
1734+
1735+ std::string sfmTempfilePath = (fs::path (outputPath) / fs::path (inputExpression).stem ()).generic_string ();
1736+ if (rangeIteration < rangeBlocksCount - 1 )
1737+ {
1738+ sfmTempfilePath += " _" + std::to_string (rangeIteration) + " tmp" ;
1739+ }
1740+ sfmTempfilePath += (fs::path (inputExpression).extension ()).generic_string ();
1741+
1742+
1743+ if (!sfmDataIO::save (sfmDataNew, sfmTempfilePath, sfmDataIO::ESfMData (sfmDataIO::ALL)))
17031744 {
17041745 ALICEVISION_LOG_ERROR (" The output SfMData file '" << sfmfilePath << " ' cannot be written." );
17051746 return EXIT_FAILURE;
17061747 }
17071748
1749+ fs::rename (sfmTempfilePath, sfmfilePath);
1750+
17081751 fs::remove (sfmfilePath_in);
17091752 }
17101753 }
0 commit comments