Skip to contentSkip to conversation

wic: fix creation of working directory

PATCH New Ed Bartosh 1 participant 4 messages Feb 2, 2017

lore
Share & tools
lore

Ed Bartosh

author
#0 lore raw

cover wic: fix creation of working directory

Hi,

Changed working directory to be subdirectory of output dir. This should fix several possible issues:
- current code uses mktemp which doesn't create anything
- default temporary directory is created in /tmp, which can cause wic to take long time to move result image as output directory can be on another partition
- possible disk space issues due to the /tmp usage

The following changes since commit 7d75fd29296a9c411881b4288bff2e02cb145a25:

wic: remove syslinux.py (2017-02-01 12:46:17 +0200)

are available in the git repository at:

git://git.yoctoproject.org/poky-contrib ed/wic/refactoring-10619
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=ed/wic/refactoring-10619

Ed Bartosh (3):
wic: engine: create output dir
wic: direct: fix creation of work directory
wic: get rid of image_output_dir variable

 scripts/lib/wic/engine.py                | 3 +++
 scripts/lib/wic/plugins/imager/direct.py | 2 +-
 scripts/wic                              | 6 +-----
 3 files changed, 5 insertions(+), 6 deletions(-)

--
2.1.4

author
#1 lore raw

PATCH 1/3 wic: engine: create output dir

Make sure output directory exists before creating an image. Create it if it doesn't exist.

---
 scripts/lib/wic/engine.py | 3 +++
 1 file changed, 3 insertions(+)
scripts/lib/wic/engine.py +3 -0
index 592ef77..7fb6f13 100644
@@ -187,6 +187,9 @@ def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
     if debug:
         msger.set_loglevel('debug')
 
+    if not os.path.exists(image_output_dir):
+        os.makedirs(image_output_dir)
+
     crobj = creator.Creator()
 
     cmdline = ["direct", native_sysroot, kernel_dir, bootimg_dir, rootfs_dir,
Signature · 1 line
2.1.4
author
#2 lore raw

PATCH 2/3 wic: direct: fix creation of work directory

In reply to Ed Bartosh

It was a typo in current code: mktemp was used instead of mkdtemp to create work directory. This is fixed by using mkdtemp.

Create work directory as a subdirectory of output directory to make sure both are on the same partition to make moving of result image faster.

This also fixes possible disk space issues as mkdtemp uses TMPDIR, TEMP or TMP environment variables to get default value of its 'dir' parameter. Those variables are usually pointing to /tmp, which is not the best location to create huge images.

---
 scripts/lib/wic/plugins/imager/direct.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/lib/wic/plugins/imager/direct.py +1 -1
index 4637fbf3..b38e876 100644
@@ -122,7 +122,7 @@ class DirectImageCreator:
         """
         self.name = name
         self.outdir = outdir
-        self.workdir = tempfile.mktemp(prefix='wic')
+        self.workdir = tempfile.mkdtemp(dir=outdir, prefix='tmp.wic.')
         self.ks = ksobj
 
         self._image = None
Signature · 1 line
2.1.4
author
#3 lore raw

PATCH 3/3 wic: get rid of image_output_dir variable

In reply to Ed Bartosh

Used options.outdir instead of image_output_dir.
There is no sense to use extra variable for this.

---
 scripts/wic | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
scripts/wic +1 -5
index 33355ee..17e8231 100755
@@ -203,10 +203,6 @@ def wic_create_subcommand(args, usage_str):
                   "kickstart (.wks) filename)\n" % args[0])
             sys.exit(1)
 
-    image_output_dir = ""
-    if options.outdir:
-        image_output_dir = options.outdir
-
     if not options.image_name:
         rootfs_dir = ''
         if 'ROOTFS_DIR' in options.rootfs_dir:
@@ -254,7 +250,7 @@ def wic_create_subcommand(args, usage_str):
 
     print("Creating image(s)...\n")
     engine.wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
-                      native_sysroot, scripts_path, image_output_dir,
+                      native_sysroot, scripts_path, options.outdir,
                       options.compressor, options.bmap, options.debug)
 
 
Signature · 1 line
2.1.4