From 03ab873e220cdf02434e7ba3dfa35ad90e7dd235 Mon Sep 17 00:00:00 2001 From: Julien BIANCHI Date: Thu, 23 Jul 2020 22:35:06 +0200 Subject: [PATCH] fix: Volume labels are correct (#49) Closes #45 --- src/functions.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/functions.php b/src/functions.php index 3de7e11..c46f8bc 100644 --- a/src/functions.php +++ b/src/functions.php @@ -309,7 +309,7 @@ function makeVerticesAndEdges(Graph $graph, array $services, array $volumes, arr $container = $volume['target']; $attr = !empty($volume['read-only']) ? 'ro' : ''; } else { - list($host, $container, $attr) = explodeMapping($volume); + list($host, $container, $attr) = explodeVolumeMapping($volume); } $serviceVolumes[$container] = [$host, $attr]; @@ -506,13 +506,23 @@ function explodeMapping($mapping): array $parts = explode(':', $mapping); $parts[1] = $parts[1] ?? $parts[0]; - $subparts = array_values(array_filter(explode('/', $parts[1]))); + return [$parts[0], $parts[1]]; +} - if (count($subparts) > 2) { - $subparts = [$parts[1], $parts[2] ?? null]; - } +/** + * @internal + * + * @param string $mapping A docker mapping ([:]) + * + * @return array An 2 or 3 items array containing the parts of the mapping. + * If the mapping does not specify a second part, the first one will be repeated + */ +function explodeVolumeMapping($mapping): array +{ + $parts = explode(':', $mapping); + $parts[1] = $parts[1] ?? $parts[0]; - return [$parts[0], $subparts[0], $subparts[1] ?? null]; + return [$parts[0], $parts[1], $parts[2] ?? null]; } /**