mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
an argument is not always needed to be passed to open a file
This commit is contained in:
parent
8a89cb2c4b
commit
6148c50781
1 changed files with 4 additions and 2 deletions
|
@ -416,11 +416,13 @@ def flopen(*args, **kwargs):
|
|||
'''
|
||||
Shortcut for fopen with lock and context manager.
|
||||
'''
|
||||
with fopen(*args, **kwargs) as f_handle:
|
||||
filename = args.pop(0)
|
||||
vars = 'wa'
|
||||
with fopen(filename, *args, **kwargs) as f_handle:
|
||||
try:
|
||||
if is_fcntl_available(check_sunos=True):
|
||||
lock_type = fcntl.LOCK_SH
|
||||
if 'w' in args[1] or 'a' in args[1]:
|
||||
if args and any([var in args[0] for var in vars]):
|
||||
lock_type = fcntl.LOCK_EX
|
||||
fcntl.flock(f_handle.fileno(), lock_type)
|
||||
yield f_handle
|
||||
|
|
Loading…
Add table
Reference in a new issue