@@ -259,10 +259,16 @@ export async function CommitIngestOperation(
259
259
}
260
260
261
261
function canRemoveSegment (
262
+ prevPartInstance : ReadonlyDeep < DBPartInstance > | undefined ,
262
263
currentPartInstance : ReadonlyDeep < DBPartInstance > | undefined ,
263
264
nextPartInstance : ReadonlyDeep < DBPartInstance > | undefined ,
264
265
segmentId : SegmentId
265
266
) : 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
+ }
266
272
if (
267
273
currentPartInstance ?. segmentId === segmentId ||
268
274
( nextPartInstance ?. segmentId === segmentId && isTooCloseToAutonext ( currentPartInstance , false ) )
@@ -662,7 +668,7 @@ async function removeSegments(
662
668
_changedSegmentIds : ReadonlyDeep < SegmentId [ ] > ,
663
669
removedSegmentIds : ReadonlyDeep < SegmentId [ ] >
664
670
) {
665
- const { currentPartInstance, nextPartInstance } = await getSelectedPartInstances (
671
+ const { previousPartInstance , currentPartInstance, nextPartInstance } = await getSelectedPartInstances (
666
672
context ,
667
673
newPlaylist ,
668
674
rundownsInPlaylist . map ( ( r ) => r . _id )
@@ -672,7 +678,7 @@ async function removeSegments(
672
678
const orphanDeletedSegmentIds = new Set < SegmentId > ( )
673
679
const orphanHiddenSegmentIds = new Set < SegmentId > ( )
674
680
for ( const segmentId of removedSegmentIds ) {
675
- if ( canRemoveSegment ( currentPartInstance , nextPartInstance , segmentId ) ) {
681
+ if ( canRemoveSegment ( previousPartInstance , currentPartInstance , nextPartInstance , segmentId ) ) {
676
682
purgeSegmentIds . add ( segmentId )
677
683
} else {
678
684
logger . warn (
@@ -685,7 +691,7 @@ async function removeSegments(
685
691
for ( const segment of ingestModel . getAllSegments ( ) ) {
686
692
const segmentId = segment . segment . _id
687
693
if ( segment . segment . isHidden ) {
688
- if ( ! canRemoveSegment ( currentPartInstance , nextPartInstance , segmentId ) ) {
694
+ if ( ! canRemoveSegment ( previousPartInstance , currentPartInstance , nextPartInstance , segmentId ) ) {
689
695
// Protect live segment from being hidden
690
696
logger . warn ( `Cannot hide live segment ${ segmentId } , it will be orphaned` )
691
697
switch ( segment . segment . orphaned ) {
@@ -706,7 +712,7 @@ async function removeSegments(
706
712
} else if ( ! orphanDeletedSegmentIds . has ( segmentId ) && segment . parts . length === 0 ) {
707
713
// No parts in segment
708
714
709
- if ( ! canRemoveSegment ( currentPartInstance , nextPartInstance , segmentId ) ) {
715
+ if ( ! canRemoveSegment ( previousPartInstance , currentPartInstance , nextPartInstance , segmentId ) ) {
710
716
// Protect live segment from being hidden
711
717
logger . warn ( `Cannot hide live segment ${ segmentId } , it will be orphaned` )
712
718
orphanHiddenSegmentIds . add ( segmentId )
0 commit comments