@@ -259,10 +259,16 @@ export async function CommitIngestOperation(
259259}
260260
261261function canRemoveSegment (
262+ prevPartInstance : ReadonlyDeep < DBPartInstance > | undefined ,
262263 currentPartInstance : ReadonlyDeep < DBPartInstance > | undefined ,
263264 nextPartInstance : ReadonlyDeep < DBPartInstance > | undefined ,
264265 segmentId : SegmentId
265266) : boolean {
267+ if ( prevPartInstance ?. segmentId === segmentId ) {
268+ // Don't allow removing an active rundown
269+ logger . warn ( `Not allowing removal of previous playing segment "${ segmentId } ", making segment unsynced instead` )
270+ return false
271+ }
266272 if (
267273 currentPartInstance ?. segmentId === segmentId ||
268274 ( nextPartInstance ?. segmentId === segmentId && isTooCloseToAutonext ( currentPartInstance , false ) )
@@ -662,7 +668,7 @@ async function removeSegments(
662668 _changedSegmentIds : ReadonlyDeep < SegmentId [ ] > ,
663669 removedSegmentIds : ReadonlyDeep < SegmentId [ ] >
664670) {
665- const { currentPartInstance, nextPartInstance } = await getSelectedPartInstances (
671+ const { previousPartInstance , currentPartInstance, nextPartInstance } = await getSelectedPartInstances (
666672 context ,
667673 newPlaylist ,
668674 rundownsInPlaylist . map ( ( r ) => r . _id )
@@ -672,7 +678,7 @@ async function removeSegments(
672678 const orphanDeletedSegmentIds = new Set < SegmentId > ( )
673679 const orphanHiddenSegmentIds = new Set < SegmentId > ( )
674680 for ( const segmentId of removedSegmentIds ) {
675- if ( canRemoveSegment ( currentPartInstance , nextPartInstance , segmentId ) ) {
681+ if ( canRemoveSegment ( previousPartInstance , currentPartInstance , nextPartInstance , segmentId ) ) {
676682 purgeSegmentIds . add ( segmentId )
677683 } else {
678684 logger . warn (
@@ -685,7 +691,7 @@ async function removeSegments(
685691 for ( const segment of ingestModel . getAllSegments ( ) ) {
686692 const segmentId = segment . segment . _id
687693 if ( segment . segment . isHidden ) {
688- if ( ! canRemoveSegment ( currentPartInstance , nextPartInstance , segmentId ) ) {
694+ if ( ! canRemoveSegment ( previousPartInstance , currentPartInstance , nextPartInstance , segmentId ) ) {
689695 // Protect live segment from being hidden
690696 logger . warn ( `Cannot hide live segment ${ segmentId } , it will be orphaned` )
691697 switch ( segment . segment . orphaned ) {
@@ -706,7 +712,7 @@ async function removeSegments(
706712 } else if ( ! orphanDeletedSegmentIds . has ( segmentId ) && segment . parts . length === 0 ) {
707713 // No parts in segment
708714
709- if ( ! canRemoveSegment ( currentPartInstance , nextPartInstance , segmentId ) ) {
715+ if ( ! canRemoveSegment ( previousPartInstance , currentPartInstance , nextPartInstance , segmentId ) ) {
710716 // Protect live segment from being hidden
711717 logger . warn ( `Cannot hide live segment ${ segmentId } , it will be orphaned` )
712718 orphanHiddenSegmentIds . add ( segmentId )
0 commit comments