os.chdir(oldoutdir)
os.unlink(path)
-def bootstrap_mic(argv=None):
+def bootstrap_mic(ksconf, argv=None):
def mychroot():
os.chroot(rootdir)
os.chdir(cwd)
argv[0] = '/usr/bin/mic'
cachedir = configmgr.create['cachedir']
+ if not os.path.exists(cachedir):
+ os.makedirs(cachedir)
+
+ cache_changed = False
cache_lock = open(os.path.join(cachedir, "__using.lock"), 'w')
try:
fcntl.flock(cache_lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
except BlockingIOError:
- raise errors.CreatorError("Cache %s is using by other mic" % cachedir)
+ for cache_option in ('-k', '--cachedir'):
+ if cache_option in argv[1:]:
+ cache_lock.close()
+ raise errors.CreatorError("Cache %s is using by other mic" % cachedir)
+
+ cachedir = tempfile.mkdtemp(prefix="ks-", dir=os.path.dirname(cachedir))
+ configmgr.create['cachedir'] = cachedir
+ argv.append('-k')
+ argv.append(cachedir)
+ cache_changed = True
+ cache_lock = open(os.path.join(cachedir, "__using.lock"), 'w')
+ fcntl.flock(cache_lock, fcntl.LOCK_EX)
+ configmgr._ksconf = ksconf
cropts = configmgr.create
bsopts = configmgr.bootstrap
distro = bsopts['distro_name'].lower()
fcntl.flock(cache_lock, fcntl.LOCK_UN)
cache_lock.close()
bsenv.cleanup()
+ if cache_changed:
+ shutil.rmtree(cachedir, ignore_errors=True)
def get_bindmounts(cropts):
binddirs = [
ksconf = args.ksfile
if creatoropts['runtime'] == 'bootstrap':
- configmgr._ksconf = ksconf
- bootstrap_mic()
+ bootstrap_mic(ksconf)
recording_pkgs = []
if len(creatoropts['record_pkgs']) > 0: