Skip to content

Commit 9510117

Browse files
committed
Maintain deterministic order in withCopyFileToContainer
`withCopyFileToContainer` can be invoked multiple times, including with one `containerPath` being prefix of another `containerPath`. This change makes the end result deterministic.
1 parent 8767b86 commit 9510117

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

core/src/main/java/org/testcontainers/containers/GenericContainer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
import java.util.HashMap;
7979
import java.util.HashSet;
8080
import java.util.Iterator;
81+
import java.util.LinkedHashMap;
8182
import java.util.LinkedHashSet;
8283
import java.util.List;
8384
import java.util.Map;
@@ -179,7 +180,8 @@ public class GenericContainer<SELF extends GenericContainer<SELF>>
179180
@Nullable
180181
private Long shmSize;
181182

182-
private Map<MountableFile, String> copyToFileContainerPathMap = new HashMap<>();
183+
// Maintain order in which entries are added, as earlier target location may be a prefix of a later location.
184+
private Map<MountableFile, String> copyToFileContainerPathMap = new LinkedHashMap<>();
183185

184186
protected final Set<Startable> dependencies = new HashSet<>();
185187

0 commit comments

Comments
 (0)