Fix exception caught when mtime_map parent dir does not exist

This fixes an exception that was introduced in 342a6ae. Also, using
os.error does not catch IOError execeptions, so this has been changed as
well.
This commit is contained in:
Erik Johnson 2013-08-30 17:18:51 -05:00
parent 3e431cc921
commit 0dda5ece20

View File

@ -85,11 +85,10 @@ def update():
os.path.join(__opts__['cachedir'], 'roots/hash'),
find_file
)
except os.error:
except (IOError, OSError):
# Hash file won't exist if no files have yet been served up
pass
mtime_map_path = os.path.join(__opts__['cachedir'], 'roots/mtime_map')
# data to send on event
data = {'changed': False,
@ -109,8 +108,10 @@ def update():
# compare the maps, set changed to the return value
data['changed'] = salt.fileserver.diff_mtime_map(old_mtime_map, new_mtime_map)
# write out the new map
mtime_map_path_dir = os.path.dirname(mtime_map_path)
if not os.path.exists(mtime_map_path_dir):
os.makedirs(mtime_map_path_dir)
with salt.utils.fopen(mtime_map_path, 'w') as fp_:
for file_path, mtime in new_mtime_map.iteritems():
fp_.write('{file_path}:{mtime}\n'.format(file_path=file_path,
@ -120,6 +121,7 @@ def update():
event = salt.utils.event.MasterEvent(__opts__['sock_dir'])
event.fire_event(data, 'salt.fileserver.roots.update')
def file_hash(load, fnd):
'''
Return a file hash, the hash type is set in the master config file