Put the file.remove in a try/except/else block

This commit is contained in:
twangboy 2017-10-11 11:17:50 -06:00
parent 020c2a2b85
commit 261dba347d
No known key found for this signature in database
GPG key ID: 93FF3BDEB278C9EB

View file

@ -46,6 +46,7 @@ import logging
import re
import locale
import ctypes
import time
# Import salt libs
import salt.utils
@ -2868,10 +2869,17 @@ def _findOptionValueInSeceditFile(option):
if _ret:
with io.open(_tfile, encoding='utf-16') as _reader:
_secdata = _reader.readlines()
while not _reader.closed:
_reader.close()
if __salt__['file.file_exists'](_tfile):
_ret = __salt__['file.remove'](_tfile)
for _ in range(5):
try:
__salt__['file.remove'](_tfile)
except WindowsError:
time.sleep(.1)
continue
else:
break
else:
log.error('error occured removing {0}'.format(_tfile))
for _line in _secdata:
if _line.startswith(option):
return True, _line.split('=')[1].strip()