@@ -547,18 +547,18 @@ SeriesInterface::flushFileBased( iterations_iterator begin, iterations_iterator
547547 if ( IOHandler ()->m_frontendAccess == Access::READ_ONLY )
548548 for ( auto it = begin; it != end; ++it )
549549 {
550+ // Phase 1
550551 switch ( openIterationIfDirty ( it->first , it->second ) )
551552 {
552553 using IO = IterationOpened;
553- case IO::RemainsClosed:
554- continue ;
555554 case IO::HasBeenOpened:
556- // continue below
555+ it->second .flush ();
556+ break ;
557+ case IO::RemainsClosed:
557558 break ;
558559 }
559560
560- it->second .flush ();
561-
561+ // Phase 2
562562 if ( *it->second .m_closed ==
563563 Iteration::CloseStatus::ClosedInFrontend )
564564 {
@@ -567,38 +567,42 @@ SeriesInterface::flushFileBased( iterations_iterator begin, iterations_iterator
567567 IOTask ( &it->second , std::move ( fClose ) ) );
568568 *it->second .m_closed = Iteration::CloseStatus::ClosedInBackend;
569569 }
570+
571+ // Phase 3
570572 IOHandler ()->flush ();
571573 }
572574 else
573575 {
574576 bool allDirty = dirty ();
575577 for ( auto it = begin; it != end; ++it )
576578 {
579+ // Phase 1
577580 switch ( openIterationIfDirty ( it->first , it->second ) )
578581 {
579582 using IO = IterationOpened;
580- case IO::RemainsClosed:
581- continue ;
582- case IO::HasBeenOpened:
583- // continue below
584- break ;
585- }
586-
587- /* as there is only one series,
588- * emulate the file belonging to each iteration as not yet written
589- */
590- written () = false ;
591- series.iterations .written () = false ;
583+ case IO::HasBeenOpened: {
584+ /* as there is only one series,
585+ * emulate the file belonging to each iteration as not yet
586+ * written
587+ */
588+ written () = false ;
589+ series.iterations .written () = false ;
592590
593- dirty () |= it->second .dirty ();
594- std::string filename = iterationFilename ( it->first );
595- it->second .flushFileBased ( filename, it->first );
591+ dirty () |= it->second .dirty ();
592+ std::string filename = iterationFilename ( it->first );
593+ it->second .flushFileBased ( filename, it->first );
596594
597- series.iterations .flush (
598- auxiliary::replace_first ( basePath (), " %T/" , " " ) );
595+ series.iterations .flush (
596+ auxiliary::replace_first ( basePath (), " %T/" , " " ) );
599597
600- flushAttributes ();
598+ flushAttributes ();
599+ break ;
600+ }
601+ case IO::RemainsClosed:
602+ break ;
603+ }
601604
605+ // Phase 2
602606 if ( *it->second .m_closed ==
603607 Iteration::CloseStatus::ClosedInFrontend )
604608 {
@@ -608,6 +612,7 @@ SeriesInterface::flushFileBased( iterations_iterator begin, iterations_iterator
608612 *it->second .m_closed = Iteration::CloseStatus::ClosedInBackend;
609613 }
610614
615+ // Phase 3
611616 IOHandler ()->flush ();
612617
613618 /* reset the dirty bit for every iteration (i.e. file)
@@ -625,23 +630,26 @@ SeriesInterface::flushGorVBased( iterations_iterator begin, iterations_iterator
625630 if ( IOHandler ()->m_frontendAccess == Access::READ_ONLY )
626631 for ( auto it = begin; it != end; ++it )
627632 {
633+ // Phase 1
628634 switch ( openIterationIfDirty ( it->first , it->second ) )
629635 {
630636 using IO = IterationOpened;
631- case IO::RemainsClosed:
632- continue ;
633637 case IO::HasBeenOpened:
634- // continue below
638+ it->second .flush ();
639+ break ;
640+ case IO::RemainsClosed:
635641 break ;
636642 }
637643
638- it-> second . flush ();
644+ // Phase 2
639645 if ( *it->second .m_closed ==
640646 Iteration::CloseStatus::ClosedInFrontend )
641647 {
642648 // the iteration has no dedicated file in group-based mode
643649 *it->second .m_closed = Iteration::CloseStatus::ClosedInBackend;
644650 }
651+
652+ // Phase 3
645653 IOHandler ()->flush ();
646654 }
647655 else
@@ -654,26 +662,23 @@ SeriesInterface::flushGorVBased( iterations_iterator begin, iterations_iterator
654662 IOHandler ()->enqueue (IOTask (this , fCreate ));
655663 }
656664
657- series.iterations .flush (auxiliary::replace_first (basePath (), " %T/" , " " ));
665+ series.iterations .flush (
666+ auxiliary::replace_first ( basePath (), " %T/" , " " ) );
658667
659668 for ( auto it = begin; it != end; ++it )
660669 {
670+ // Phase 1
661671 switch ( openIterationIfDirty ( it->first , it->second ) )
662672 {
663673 using IO = IterationOpened;
664- case IO::RemainsClosed:
665- continue ;
666674 case IO::HasBeenOpened:
667- // continue below
668- break ;
669- }
670- if ( !it->second .written () )
671- {
672- it->second .parent () = getWritable ( &series.iterations );
673- }
674- switch ( iterationEncoding () )
675- {
676- using IE = IterationEncoding;
675+ if ( !it->second .written () )
676+ {
677+ it->second .parent () = getWritable ( &series.iterations );
678+ }
679+ switch ( iterationEncoding () )
680+ {
681+ using IE = IterationEncoding;
677682 case IE::groupBased:
678683 it->second .flushGroupBased ( it->first );
679684 break ;
@@ -683,8 +688,15 @@ SeriesInterface::flushGorVBased( iterations_iterator begin, iterations_iterator
683688 default :
684689 throw std::runtime_error (
685690 " [Series] Internal control flow error" );
691+ }
692+ break ;
693+ case IO::RemainsClosed:
694+ break ;
686695 }
687- if ( *it->second .m_closed == Iteration::CloseStatus::ClosedInFrontend )
696+
697+ // Phase 2
698+ if ( *it->second .m_closed ==
699+ Iteration::CloseStatus::ClosedInFrontend )
688700 {
689701 // the iteration has no dedicated file in group-based mode
690702 *it->second .m_closed = Iteration::CloseStatus::ClosedInBackend;
0 commit comments