Commit 9a4e60c7 authored by Yusei Tahara's avatar Yusei Tahara

To check shared directory is not enough. Shared directory may be created...

To check shared directory is not enough. Shared directory may be created before completing installation. Check signature file too.
parent bd91037f
......@@ -40,30 +40,24 @@ class Recipe(object):
self.original_options = options.copy()
options.update(platform_options)
shared = options.get('shared', '').lower()
if shared == 'true' and buildout['buildout'].get('shared-parts', None):
shared = ((options.get('shared', '').lower() == 'true') and
buildout['buildout'].get('shared-parts', None))
if shared:
shared_part = buildout['buildout'].get('shared-parts', None)
shared = os.path.join(shared_part.strip().rstrip('/'), self.name)
if not os.path.exists(shared):
os.makedirs(shared)
self._debug_signature_text = []
# compute hash from options
m = md5()
self._signature = slapos.recipe.downloadunpacked.Signature('.slapos.recipe.cmmi.signature')
buildout_directory = buildout['buildout']['directory']
profile_base_location = options.get('_profile_base_location_', '')
for k, v in sorted(options.items()):
# Key not vary on profile base location
if profile_base_location:
v = v.replace(profile_base_location, '${:_profile_base_location_}')
option_signature = ('%r: %r' % (k, v)).encode()
log.debug("Updating hash with %s", option_signature)
self._debug_signature_text.append(option_signature)
# Or maybe warn and disable cache
assert buildout_directory not in option_signature
m.update(option_signature)
shared = os.path.join(shared, m.hexdigest())
self._signature.update(k, v)
shared = os.path.join(shared, self._signature.hexdigest())
log.info('shared directory %s set for %s', shared, self.name)
else:
shared = ''
......@@ -285,7 +279,7 @@ class Recipe(object):
# In shared mode, do nothing if package has been installed.
if (not self.options['shared'] == ''):
log.info('Checking whether package is installed at shared path: %s', self.options['shared'])
if os.path.exists(self.options['shared']):
if self._signature.test(self.options['shared']):
log.info('This shared package has been installed by other package')
return parts
......@@ -348,12 +342,8 @@ class Recipe(object):
shutil.rmtree(tmp_path, True)
os.mkdir(tmp_path)
# Create a debug file with the signatures.
if self.options['shared']:
with open(os.path.join(
self.options["shared"],
".slapos.recipe.cmmi.signature"), 'w') as f:
f.write('\n'.join(self._debug_signature_text))
self._signature.save(self.options["shared"])
try:
try:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment