File tree Expand file tree Collapse file tree 2 files changed +41
-9
lines changed Expand file tree Collapse file tree 2 files changed +41
-9
lines changed Original file line number Diff line number Diff line change @@ -355,7 +355,7 @@ func ensureOCIHooks(spec *oci.Spec) {
355
355
func sortMounts (specgen * ocigen.Generator ) {
356
356
mounts := specgen .Mounts ()
357
357
specgen .ClearMounts ()
358
- sort .Sort (orderedMounts (mounts ))
358
+ sort .Stable (orderedMounts (mounts ))
359
359
specgen .Config .Mounts = mounts
360
360
}
361
361
@@ -375,14 +375,7 @@ func (m orderedMounts) Len() int {
375
375
// mount indexed by parameter 1 is less than that of the mount indexed by
376
376
// parameter 2. Used in sorting.
377
377
func (m orderedMounts ) Less (i , j int ) bool {
378
- ip , jp := m .parts (i ), m .parts (j )
379
- if ip < jp {
380
- return true
381
- }
382
- if jp < ip {
383
- return false
384
- }
385
- return m [i ].Destination < m [j ].Destination
378
+ return m .parts (i ) < m .parts (j )
386
379
}
387
380
388
381
// Swap swaps two items in an array of mounts. Used in sorting
Original file line number Diff line number Diff line change @@ -599,6 +599,45 @@ func TestApplyContainerEdits(t *testing.T) {
599
599
},
600
600
result : & oci.Spec {},
601
601
},
602
+ {
603
+ name : "apply mount edits do not change the order of original mounts" ,
604
+ spec : & oci.Spec {
605
+ Mounts : []oci.Mount {
606
+ {
607
+ Source : "/some/host/path1" ,
608
+ Destination : "/dest/path/b" ,
609
+ },
610
+ {
611
+ Source : "/some/host/path2" ,
612
+ Destination : "/dest/path/a" ,
613
+ },
614
+ },
615
+ },
616
+ edits : & cdi.ContainerEdits {
617
+ Mounts : []* cdi.Mount {
618
+ {
619
+ HostPath : "/some/host/path3" ,
620
+ ContainerPath : "/dest/edit" ,
621
+ },
622
+ },
623
+ },
624
+ result : & oci.Spec {
625
+ Mounts : []oci.Mount {
626
+ {
627
+ Source : "/some/host/path3" ,
628
+ Destination : "/dest/edit" ,
629
+ },
630
+ {
631
+ Source : "/some/host/path1" ,
632
+ Destination : "/dest/path/b" ,
633
+ },
634
+ {
635
+ Source : "/some/host/path2" ,
636
+ Destination : "/dest/path/a" ,
637
+ },
638
+ },
639
+ },
640
+ },
602
641
} {
603
642
t .Run (tc .name , func (t * testing.T ) {
604
643
edits := ContainerEdits {tc .edits }
You can’t perform that action at this time.
0 commit comments