summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2017-01-24 15:43:51 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-01-31 14:12:47 +0000
commit5d948f04823dedfa26a879aa6a5dc23de2bb9354 (patch)
tree7b171cddc5edbd676c42c0d369fd87483dffe084 /scripts
parent4e9952514211ef4b9a3731ce915090385f335a31 (diff)
downloadopenembedded-core-5d948f04823dedfa26a879aa6a5dc23de2bb9354.tar.gz
openembedded-core-5d948f04823dedfa26a879aa6a5dc23de2bb9354.tar.bz2
openembedded-core-5d948f04823dedfa26a879aa6a5dc23de2bb9354.zip
wic: make workdir a temporary directory
Wic used hardcoded path /var/tmp/wic/ as a work directory, which caused conflicts if two wic instances run in parallel. Made work directory unique and temporary. Moved results from work directory to output directory when they're ready. [YOCTO #10783] Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib/wic/imager/direct.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/scripts/lib/wic/imager/direct.py b/scripts/lib/wic/imager/direct.py
index 825c9d7f6e..63f1fa1d39 100644
--- a/scripts/lib/wic/imager/direct.py
+++ b/scripts/lib/wic/imager/direct.py
@@ -27,6 +27,7 @@
import os
import shutil
import uuid
+import tempfile
from wic import msger
from wic.utils.oe.misc import get_bitbake_var
@@ -79,16 +80,11 @@ class DirectImageCreator:
This method takes the same arguments as ImageCreator.__init__()
"""
-
self.name = creatoropts['name']
+ self.outdir = image_output_dir
+ self.workdir = tempfile.mktemp(prefix='wic')
self.ks = creatoropts['ks']
- self.tmpdir = "/var/tmp/wic"
- self.workdir = "/var/tmp/wic/build"
-
- if not os.path.exists(self.tmpdir):
- os.makedirs(self.tmpdir)
-
self.__image = None
self.__disks = {}
self.__disk_format = "direct"
@@ -96,8 +92,6 @@ class DirectImageCreator:
self.ptable_format = self.ks.bootloader.ptable
self.oe_builddir = oe_builddir
- if image_output_dir:
- self.tmpdir = image_output_dir
self.rootfs_dir = rootfs_dir
self.bootimg_dir = bootimg_dir
self.kernel_dir = kernel_dir
@@ -270,9 +264,6 @@ class DirectImageCreator:
fstab_path = self._write_fstab(self.rootfs_dir.get("ROOTFS_DIR"))
- shutil.rmtree(self.workdir)
- os.mkdir(self.workdir)
-
for part in parts:
# get rootfs size from bitbake variable if it's not set in .ks file
if not part.size:
@@ -425,3 +416,15 @@ class DirectImageCreator:
except ImageError as err:
msger.warning("%s" % err)
+ # Move results to the output dir
+ if not os.path.exists(self.outdir):
+ os.makedirs(self.outdir)
+
+ for fname in os.listdir(self.workdir):
+ path = os.path.join(self.workdir, fname)
+ if os.path.isfile(path):
+ shutil.move(path, os.path.join(self.outdir, fname))
+
+ # remove work directory
+ shutil.rmtree(self.workdir, ignore_errors=True)
+