mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
fixed exception handling to be 2.4 compatible
previous 'fix' broke on 2.4
This commit is contained in:
parent
1f7492171e
commit
a773486432
1 changed files with 11 additions and 9 deletions
|
@ -2980,6 +2980,7 @@ class SunOSVirtual(Virtual):
|
||||||
def get_file_content(path, default=None, strip=True):
|
def get_file_content(path, default=None, strip=True):
|
||||||
data = default
|
data = default
|
||||||
if os.path.exists(path) and os.access(path, os.R_OK):
|
if os.path.exists(path) and os.access(path, os.R_OK):
|
||||||
|
try:
|
||||||
try:
|
try:
|
||||||
datafile = open(path)
|
datafile = open(path)
|
||||||
data = datafile.read()
|
data = datafile.read()
|
||||||
|
@ -2987,11 +2988,12 @@ def get_file_content(path, default=None, strip=True):
|
||||||
data = data.strip()
|
data = data.strip()
|
||||||
if len(data) == 0:
|
if len(data) == 0:
|
||||||
data = default
|
data = default
|
||||||
except:
|
|
||||||
# todo: issue warning about unreadable file?
|
|
||||||
pass
|
|
||||||
finally:
|
finally:
|
||||||
datafile.close()
|
datafile.close()
|
||||||
|
except:
|
||||||
|
# ignore errors as some jails/containers might have readable permissions but not allow reads to proc
|
||||||
|
# done in 2 blocks for 2.4 compat
|
||||||
|
pass
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def get_file_lines(path):
|
def get_file_lines(path):
|
||||||
|
|
Loading…
Reference in a new issue