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): ...@@ -40,30 +40,24 @@ class Recipe(object):
self.original_options = options.copy() self.original_options = options.copy()
options.update(platform_options) options.update(platform_options)
shared = options.get('shared', '').lower() shared = ((options.get('shared', '').lower() == 'true') and
if shared == 'true' and buildout['buildout'].get('shared-parts', None): buildout['buildout'].get('shared-parts', None))
if shared:
shared_part = buildout['buildout'].get('shared-parts', None) shared_part = buildout['buildout'].get('shared-parts', None)
shared = os.path.join(shared_part.strip().rstrip('/'), self.name) shared = os.path.join(shared_part.strip().rstrip('/'), self.name)
if not os.path.exists(shared): if not os.path.exists(shared):
os.makedirs(shared) os.makedirs(shared)
self._debug_signature_text = [] self._signature = slapos.recipe.downloadunpacked.Signature('.slapos.recipe.cmmi.signature')
# compute hash from options
m = md5()
buildout_directory = buildout['buildout']['directory'] buildout_directory = buildout['buildout']['directory']
profile_base_location = options.get('_profile_base_location_', '') profile_base_location = options.get('_profile_base_location_', '')
for k, v in sorted(options.items()): for k, v in sorted(options.items()):
# Key not vary on profile base location # Key not vary on profile base location
if profile_base_location: if profile_base_location:
v = v.replace(profile_base_location, '${:_profile_base_location_}') v = v.replace(profile_base_location, '${:_profile_base_location_}')
option_signature = ('%r: %r' % (k, v)).encode() self._signature.update(k, v)
log.debug("Updating hash with %s", option_signature)
self._debug_signature_text.append(option_signature) shared = os.path.join(shared, self._signature.hexdigest())
# Or maybe warn and disable cache
assert buildout_directory not in option_signature
m.update(option_signature)
shared = os.path.join(shared, m.hexdigest())
log.info('shared directory %s set for %s', shared, self.name) log.info('shared directory %s set for %s', shared, self.name)
else: else:
shared = '' shared = ''
...@@ -285,7 +279,7 @@ class Recipe(object): ...@@ -285,7 +279,7 @@ class Recipe(object):
# In shared mode, do nothing if package has been installed. # In shared mode, do nothing if package has been installed.
if (not self.options['shared'] == ''): if (not self.options['shared'] == ''):
log.info('Checking whether package is installed at shared path: %s', 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') log.info('This shared package has been installed by other package')
return parts return parts
...@@ -348,12 +342,8 @@ class Recipe(object): ...@@ -348,12 +342,8 @@ class Recipe(object):
shutil.rmtree(tmp_path, True) shutil.rmtree(tmp_path, True)
os.mkdir(tmp_path) os.mkdir(tmp_path)
# Create a debug file with the signatures.
if self.options['shared']: if self.options['shared']:
with open(os.path.join( self._signature.save(self.options["shared"])
self.options["shared"],
".slapos.recipe.cmmi.signature"), 'w') as f:
f.write('\n'.join(self._debug_signature_text))
try: try:
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