Skip to content

Commit 2edcaff

Browse files
authored
fix(controller): fix multiple volumes mount at one dir error (#116)
1 parent 868ebe1 commit 2edcaff

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

rootfs/api/serializers.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -586,17 +586,23 @@ def validate_size(data):
586586

587587
@staticmethod
588588
def validate_path(data):
589+
logger.debug(f"mount validate_path data: {data}")
590+
new_data = {}
589591
for key, value in data.items():
590-
if value is None: # use NoneType to unset an item
591-
continue
592-
593592
if not re.match(PROCTYPE_MATCH, key):
594593
raise serializers.ValidationError(PROCTYPE_MISMATCH_MSG)
594+
if value is None: # use NoneType to unset an item
595+
new_data[key] = value
596+
continue
595597

596598
if not re.match(VOLUME_PATH, str(value)):
597599
raise serializers.ValidationError(
598600
"Volume path format: /path")
599-
return data
601+
if value.endswith("/"):
602+
value = value.rstrip("/")
603+
new_data[key] = value
604+
logger.debug(f"mount validate_path new_data: {new_data}")
605+
return new_data
600606

601607

602608
class ResourceSerializer(serializers.ModelSerializer):

rootfs/api/views.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def run(self, request, **kwargs):
269269
raise DryccException("command is a required field")
270270
volumes = request.data.get('volumes', None)
271271
if volumes:
272-
serializers.VolumeSerializer().validate_path(volumes)
272+
volumes = serializers.VolumeSerializer().validate_path(volumes)
273273
rc, output = app.run(self.request.user, request.data['command'], volumes)
274274
return Response({'exit_code': rc, 'output': str(output)})
275275

@@ -717,6 +717,8 @@ def path(self, request, *args, **kwargs):
717717
new_path = request.data.get('path')
718718
if new_path is None:
719719
raise DryccException("path is a required field")
720+
else:
721+
new_path = serializers.VolumeSerializer().validate_path(new_path)
720722
volume = self.get_object()
721723
container_types = [_ for _ in new_path.keys()
722724
if _ not in volume.app.types]
@@ -734,7 +736,7 @@ def path(self, request, *args, **kwargs):
734736
if k not in type_paths:
735737
type_paths[k] = [v]
736738
else:
737-
type_paths[k].append(k)
739+
type_paths[k].append(v)
738740
repeat_path = [v for k, v in new_path.items() if v in type_paths.get(k, [])] # noqa
739741
if repeat_path:
740742
raise DryccException("path {} is used by another volume".

0 commit comments

Comments
 (0)