|
12 | 12 | import javax.annotation.Nonnull;
|
13 | 13 | import java.io.*;
|
14 | 14 | import java.nio.charset.Charset;
|
| 15 | +import java.nio.file.InvalidPathException; |
| 16 | +import java.nio.file.Path; |
| 17 | +import java.nio.file.Paths; |
15 | 18 | import java.util.*;
|
16 | 19 | import java.util.concurrent.TimeUnit;
|
17 | 20 | import java.util.logging.Level;
|
@@ -39,8 +42,38 @@ public String run(@Nonnull EnvVars launchEnv, @Nonnull String image, @CheckForNu
|
39 | 42 | if (workdir != null) {
|
40 | 43 | argb.add("-w", workdir);
|
41 | 44 | }
|
| 45 | + Set<String> drives = new HashSet<>(); |
42 | 46 | for (Map.Entry<String, String> volume : volumes.entrySet()) {
|
43 |
| - argb.add("-v", volume.getKey() + ":" + volume.getValue()); |
| 47 | + String driveName = null; |
| 48 | + |
| 49 | + try { |
| 50 | + Path hostPath = Paths.get(volume.getKey()); |
| 51 | + Path rootPath = hostPath.getRoot(); |
| 52 | + // If we have a valid root we can check if we need to do our special root handling |
| 53 | + if (rootPath != null) { |
| 54 | + driveName = rootPath.toString(); |
| 55 | + if (driveName.endsWith("\\")) { |
| 56 | + driveName = driveName.substring(0, driveName.length() - 1); |
| 57 | + } |
| 58 | + } |
| 59 | + } catch (InvalidPathException e) { |
| 60 | + // We got a value that is not a valid path. Keeping driveName at null allows us to gracefully handle this |
| 61 | + // and skip the special drive path handling for those cases |
| 62 | + } |
| 63 | + if (driveName == null || driveName.equals("C:")) { |
| 64 | + // C: path can be mapped directly |
| 65 | + argb.add("-v", volume.getKey() + ":" + volume.getValue()); |
| 66 | + } |
| 67 | + else |
| 68 | + { |
| 69 | + // Non C: drive paths in the container can not be mapped due to Windows limitations. It is only possible |
| 70 | + // to map an entire drive so we collect the used drives and map the entire drive |
| 71 | + drives.add(driveName); |
| 72 | + } |
| 73 | + } |
| 74 | + for (String drive : drives) { |
| 75 | + // Windows requires that the host part is a directory but the container path must be an entire drive |
| 76 | + argb.add("-v", String.format("%s\\:%s", drive, drive)); |
44 | 77 | }
|
45 | 78 | for (String containerId : volumesFromContainers) {
|
46 | 79 | argb.add("--volumes-from", containerId);
|
|
0 commit comments