-
Notifications
You must be signed in to change notification settings - Fork 5.5k
"salt.utils.fopen(path, 'rb')" may cause error #16751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you demonstrate where this causes a problem? We've been over this code extensively. Not opening files in Binary mode on Windows causes a lot of trouble for most Python software that needs to run on both Windows and Unix-like machines. |
when I call "saltutil.running" function: a error throw: salt 'test' saltutil.running Part of code of function _read_proc_file: ---------------code begin------------------------------------- def _read_proc_file(path):
'''
Return a dict of JID metadata, or None
'''
with salt.utils.fopen(path, 'rb') as fp_:
buf = fp_.read()
fp_.close()
if buf:
data = serial.loads(buf)
else: --------------code finish------------------------------------------ look into the salt/modules/saltutil.py line 425, this problem is cause by 'buf = fp_.read()', the buffer contains an additional '\r', leads exception in line 425(data = serial.loads(buf)), If use 'r' mode, serial.loads success because no more '\r' in buf. The original file just contains the '\n' |
The issue is that the file was writing in text mode, not that it's being read in binary mode. |
@olliewalsh, It is written in w+b mode,see below salt\minion.py
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue. |
here is my scene:
in salt\modules\saltutil.py line 421 ,
----------------------------------------------------code finish-------------------------------------------------
if path's file'content is:
劊fun玬ine.updateid?0141017165429682000id?
寓idVR6175
if use 'rb' mode to read the file,buf will be:
劊fun玬ine.updateid?0141017165429682000id?
寓idVR6175
The content readed contain a '\r' more than the orginal content(on windows 7 plat-form, '\n' will change to '\r\n' through the open(file,'rb').read() ), and this cause a error when the file is mspack's format,because an additional '\r' causes mspack loading failed.
But I try to modify the 'rb' mode to 'r' mode, the problem miss. ('\n' still to be '\n' through the open(file,'r').read() )
So is it a real problem?
The text was updated successfully, but these errors were encountered: