diff --git a/xCAT-server/lib/xcat/plugins/anaconda.pm b/xCAT-server/lib/xcat/plugins/anaconda.pm index 6f9290c44..8c98efe53 100644 --- a/xCAT-server/lib/xcat/plugins/anaconda.pm +++ b/xCAT-server/lib/xcat/plugins/anaconda.pm @@ -20,6 +20,7 @@ Getopt::Long::Configure("bundling"); Getopt::Long::Configure("pass_through"); use File::Path; use File::Copy; +use File::Temp qw/mkdtemp/; use Socket; @@ -1271,10 +1272,7 @@ sub insert_dd { } # Create the tmp dir for dd hack - my $dd_dir = "/tmp/dd_tmp"; - if (-d $dd_dir) { - rmtree "$dd_dir"; - } + my $dd_dir = mkdtemp("/tmp/ddtmpXXXXXXX"); mkpath "$dd_dir/initrd_img"; # The dir for the new initrd # unzip the initrd image diff --git a/xCAT-server/lib/xcat/plugins/sles.pm b/xCAT-server/lib/xcat/plugins/sles.pm index 9afacc3a7..d29bf70f0 100644 --- a/xCAT-server/lib/xcat/plugins/sles.pm +++ b/xCAT-server/lib/xcat/plugins/sles.pm @@ -19,6 +19,7 @@ Getopt::Long::Configure("bundling"); Getopt::Long::Configure("pass_through"); use File::Path; use File::Copy; +use File::Temp qw/mkdtemp/; use Socket; @@ -1036,7 +1037,6 @@ sub insert_dd { my $arch = shift; my $img = shift; - my $dd_dir = "/tmp/dd_tmp"; my $install_dir = xCAT::Utils->getInstallDir(); # Find out the dirver disk which need to be insert into initrd @@ -1051,9 +1051,7 @@ sub insert_dd { } # Create the tmp dir for dd hack - if (-d $dd_dir) { - rmtree "$dd_dir"; - } + my $dd_dir = mkdtemp("/tmp/ddtmpXXXXXXX"); mkpath "$dd_dir/initrd_img"; diff --git a/xCAT-server/share/xcat/netboot/rh/genimage b/xCAT-server/share/xcat/netboot/rh/genimage index a55df5085..0f202f48a 100755 --- a/xCAT-server/share/xcat/netboot/rh/genimage +++ b/xCAT-server/share/xcat/netboot/rh/genimage @@ -13,6 +13,7 @@ use File::Copy qw/copy cp mv move/; use File::Find; use Getopt::Long; use Cwd qw(realpath); +use File::Temp qw/mkdtemp/; use imgutils; @@ -1350,16 +1351,7 @@ sub load_dd () } # Create the work space for initrd hack - my $dd_dir = "/tmp/dd_tmp"; - - # If $dd_dir was not cleaned, try to umount mnt first - if (-d "$dd_dir/mnt") { - system ("umount $dd_dir/mnt >/dev/null 2>&1"); - } - if( -d "$dd_dir") { - rmtree "$dd_dir"; - } - mkpath "$dd_dir"; + my $dd_dir = mkdtemp("/tmp/ddtmpXXXXXXX"); mkpath "$dd_dir/mnt"; mkpath "$dd_dir/mods"; diff --git a/xCAT-server/share/xcat/netboot/sles/genimage b/xCAT-server/share/xcat/netboot/sles/genimage index 405024181..25828479f 100755 --- a/xCAT-server/share/xcat/netboot/sles/genimage +++ b/xCAT-server/share/xcat/netboot/sles/genimage @@ -13,6 +13,7 @@ use File::Copy; use File::Find; use Getopt::Long; use Cwd qw(realpath); +use File::Temp qw/mkdtemp/; use imgutils; @@ -1318,18 +1319,7 @@ sub load_dd() } # Create the work space, it should be cleaned at end of genimage - my $dd_dir = "/tmp/dd_tmp"; - - - # If $dd_dir was not cleaned, try to unmount mnt first - if (-d "$dd_dir/mnt") { - system ("umount $dd_dir/mnt >/dev/null 2>&1"); - } - if( -d "$dd_dir") { - rmtree "$dd_dir"; - } - - mkpath "$dd_dir"; + my $dd_dir = mkdtemp("/tmp/ddtmpXXXXXXX"); mkpath "$dd_dir/mnt"; mkpath "$dd_dir/mods";