Pino Toscano
2014-Feb-24 14:42 UTC
[Libguestfs] [PATCH] sysprep: use Mkdtemp to create the temporary directory
Use the safer mkdtemp instead of manually creating a path. --- sysprep/Makefile.am | 2 ++ sysprep/sysprep_operation_script.ml | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am index 2600477..9c9ab14 100644 --- a/sysprep/Makefile.am +++ b/sysprep/Makefile.am @@ -100,6 +100,8 @@ OBJECTS = \ $(top_builddir)/mllib/timezone.cmx \ $(top_builddir)/mllib/firstboot.cmx \ $(top_builddir)/mllib/config.cmx \ + $(top_builddir)/mllib/mkdtemp-c.o \ + $(top_builddir)/mllib/mkdtemp.cmx \ sysprep_operation.cmx \ $(patsubst %,sysprep_operation_%.cmx,$(operations)) \ main.cmx diff --git a/sysprep/sysprep_operation_script.ml b/sysprep/sysprep_operation_script.ml index 518207e..614910f 100644 --- a/sysprep/sysprep_operation_script.ml +++ b/sysprep/sysprep_operation_script.ml @@ -44,9 +44,7 @@ let rec script_perform (g : Guestfs.guestfs) root side_effects match !scriptdir with | Some dir -> dir, false | None -> - let tmpdir = Filename.temp_dir_name in - let tmpdir = tmpdir // string_random8 () in - mkdir tmpdir 0o755; + let tmpdir = Mkdtemp.mkdtemp (Filename.temp_dir_name // "virt-sysprep.XXXXXX") in tmpdir, true in (* Mount the directory locally. *) -- 1.8.3.1
Richard W.M. Jones
2014-Feb-24 15:17 UTC
Re: [Libguestfs] [PATCH] sysprep: use Mkdtemp to create the temporary directory
On Mon, Feb 24, 2014 at 03:42:03PM +0100, Pino Toscano wrote:> Use the safer mkdtemp instead of manually creating a path. > --- > sysprep/Makefile.am | 2 ++ > sysprep/sysprep_operation_script.ml | 4 +--- > 2 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am > index 2600477..9c9ab14 100644 > --- a/sysprep/Makefile.am > +++ b/sysprep/Makefile.am > @@ -100,6 +100,8 @@ OBJECTS = \ > $(top_builddir)/mllib/timezone.cmx \ > $(top_builddir)/mllib/firstboot.cmx \ > $(top_builddir)/mllib/config.cmx \ > + $(top_builddir)/mllib/mkdtemp-c.o \ > + $(top_builddir)/mllib/mkdtemp.cmx \ > sysprep_operation.cmx \ > $(patsubst %,sysprep_operation_%.cmx,$(operations)) \ > main.cmx > diff --git a/sysprep/sysprep_operation_script.ml b/sysprep/sysprep_operation_script.ml > index 518207e..614910f 100644 > --- a/sysprep/sysprep_operation_script.ml > +++ b/sysprep/sysprep_operation_script.ml > @@ -44,9 +44,7 @@ let rec script_perform (g : Guestfs.guestfs) root side_effects > match !scriptdir with > | Some dir -> dir, false > | None -> > - let tmpdir = Filename.temp_dir_name in > - let tmpdir = tmpdir // string_random8 () in > - mkdir tmpdir 0o755; > + let tmpdir = Mkdtemp.mkdtemp (Filename.temp_dir_name // "virt-sysprep.XXXXXX") in > tmpdir, true in > > (* Mount the directory locally. *) > -- > 1.8.3.1ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 80 OCaml packages (the OPEN alternative to F#)