spm updates

- add hash_file() routine to salt.spm.pkgfiles.local
- use os.path.exists() instead of pkgfiles.path.exists() in
  _local_install()
This commit is contained in:
Michael Steed 2015-09-03 14:28:21 -06:00
parent ef76af9596
commit a42651fb38
3 changed files with 23 additions and 14 deletions

View File

@ -137,7 +137,7 @@ class SPMClient(object):
raise SPMInvocationError('A package file must be specified')
pkg_file = args[1]
if not self.pkgfiles['{0}.path_exists'.format(self.files_prov)](pkg_file):
if not os.path.exists(pkg_file):
raise SPMInvocationError('Package file {0} not found'.format(pkg_file))
comps = pkg_file.split('-')
@ -413,16 +413,14 @@ class SPMClient(object):
if self.pkgfiles['{0}.path_isdir'.format(self.files_prov)](filerow[0]):
dirs.append(filerow[0])
continue
with salt.utils.fopen(filerow[0], 'r') as fh_:
file_hash = hashlib.sha1()
file_hash.update(fh_.read())
digest = file_hash.hexdigest()
if filerow[1] == digest:
log.trace('Removing file {0}'.format(filerow[0]))
self.pkgfiles['{0}.remove_file'.format(self.files_prov)](filerow[0], self.files_conn)
else:
log.trace('Not removing file {0}'.format(filerow[0]))
self.pkgdb['{0}.unregister_file'.format(self.db_prov)](filerow[0], package, self.db_conn)
file_hash = hashlib.sha1()
digest = self.pkgfiles['{0}.hash_file'.format(self.files_prov)](filerow[0], file_hash, self.files_conn)
if filerow[1] == digest:
log.trace('Removing file {0}'.format(filerow[0]))
self.pkgfiles['{0}.remove_file'.format(self.files_prov)](filerow[0], self.files_conn)
else:
log.trace('Not removing file {0}'.format(filerow[0]))
self.pkgdb['{0}.unregister_file'.format(self.db_prov)](filerow[0], package, self.db_conn)
# Clean up directories
for dir_ in sorted(dirs, reverse=True):

View File

@ -123,6 +123,15 @@ def remove_file(path, conn=None):
os.remove(path)
def hash_file(path, hashobj, conn=None):
'''
Get the hexdigest hash value of a file
'''
with salt.utils.fopen(path, 'r') as f:
hashobj.update(f.read())
return hashobj.hexdigest()
def path_exists(path):
'''
Check to see whether the file already exists

View File

@ -29,11 +29,13 @@ __opts__ = {
'spm_build_dir': os.path.join(_TMP_SPM, 'build'),
'spm_build_exclude': ['.git'],
'spm_db_provider': 'sqlite3',
'spm_files_provider': 'roots',
'spm_files_provider': 'local',
'spm_db': os.path.join(_TMP_SPM, 'packages.db'),
'extension_modules': os.path.join(_TMP_SPM, 'modules'),
'file_roots': {'base': [os.path.join(_TMP_SPM, 'salt')]},
'pillar_roots': {'base': [os.path.join(_TMP_SPM, 'pillar')]},
'file_roots': {'base': [_TMP_SPM,]},
'formula_path': os.path.join(_TMP_SPM, 'spm'),
'pillar_path': os.path.join(_TMP_SPM, 'pillar'),
'reactor_path': os.path.join(_TMP_SPM, 'reactor'),
'assume_yes': True,
'force': False,
}