Fix race condition while creating dest dir for docker images 32/114932/1
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>
Mon, 16 Nov 2020 14:39:08 +0000 (15:39 +0100)
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>
Mon, 16 Nov 2020 14:39:08 +0000 (15:39 +0100)
Docker_downloader module uses threads to concurrently save
docker images to dest dir which creation is not guarded with any
kind of thread lock object thus it could fail on os.makedirs as other
thread could have already created that dir. Hence "exist_ok=True"
opt is added to os.makedirs call so that it does not fail in such
circumstances.

Change-Id: I6e2d2c9864b71d038e7b2ed3018cdd3c01916956
Issue-ID: OOM-2631
Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
build/download/docker_downloader.py

index 27dde12..847bc18 100755 (executable)
@@ -168,8 +168,7 @@ class DockerDownloader(ConcurrentDownloader):
         :param image_name: name of the image from list
         """
         dst = '{}/{}'.format(output_dir, self._image_filename(image_name))
-        if not os.path.exists(output_dir):
-            os.makedirs(output_dir)
+        os.makedirs(output_dir, exist_ok=True)
         try:
             with open(dst, 'wb') as f:
                 for chunk in image.save(named=self.image_registry_name(image_name)):