Use try..finally blocks to ensure calls within context manager
This commit is contained in:
@@ -108,8 +108,10 @@ def change_umask():
|
|||||||
"""Creates a context manager in which the umask is changed. This is to ensure that
|
"""Creates a context manager in which the umask is changed. This is to ensure that
|
||||||
the script's desired umask is not visible to the user.
|
the script's desired umask is not visible to the user.
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
old_umask = os.umask(SCRIPT_UMASK)
|
old_umask = os.umask(SCRIPT_UMASK)
|
||||||
yield
|
yield
|
||||||
|
finally:
|
||||||
os.umask(old_umask)
|
os.umask(old_umask)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -95,8 +95,11 @@ def merge_include_files():
|
|||||||
|
|
||||||
:return: path-like object
|
:return: path-like object
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
|
# filelist is guaranteed to exist at this point
|
||||||
filelist = merge_files(get_files_by_suffix("-include.conf"))
|
filelist = merge_files(get_files_by_suffix("-include.conf"))
|
||||||
yield filelist
|
yield filelist
|
||||||
|
finally:
|
||||||
filelist.unlink()
|
filelist.unlink()
|
||||||
|
|
||||||
|
|
||||||
@@ -106,8 +109,11 @@ def merge_exclude_files():
|
|||||||
|
|
||||||
:return: path-like object
|
:return: path-like object
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
|
# filelist is guaranteed to exist at this point
|
||||||
filelist = merge_files(get_files_by_suffix("-exclude.conf"))
|
filelist = merge_files(get_files_by_suffix("-exclude.conf"))
|
||||||
yield filelist
|
yield filelist
|
||||||
|
finally:
|
||||||
filelist.unlink()
|
filelist.unlink()
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user