mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
always use binary file write mode on windows
At the event of this commit there are, including tests, 626 uses of salt.utils.fopen in the salt codebase, 477 of which do not set binary mode. Files should always be written in binary mode on windows, so ensure it always there for windows. It most likely would not be a problem for other systems, but to be safe, only set it for windows. As it is required on windows, we can solve all occurrences and potential occurrences of this problem in one place.
This commit is contained in:
parent
cdf421b9ed
commit
a978f5c091
1 changed files with 13 additions and 0 deletions
|
@ -1028,6 +1028,19 @@ def fopen(*args, **kwargs):
|
|||
)
|
||||
return flopen(*args, **kwargs)
|
||||
|
||||
# ensure 'binary' mode is always used on windows
|
||||
if is_windows():
|
||||
if len(args) > 1:
|
||||
args = list(args)
|
||||
if 'b' not in args[1]:
|
||||
args[1] += 'b'
|
||||
elif kwargs.get('mode', None):
|
||||
if 'b' not in kwargs['mode']:
|
||||
kwargs['mode'] += 'b'
|
||||
else:
|
||||
# the default is to read
|
||||
kwargs['mode'] = 'rb'
|
||||
|
||||
fhandle = open(*args, **kwargs)
|
||||
if is_fcntl_available():
|
||||
# modify the file descriptor on systems with fcntl
|
||||
|
|
Loading…
Add table
Reference in a new issue