Sandip Bhattacharya
unread,May 30, 2014, 5:31:33 PM5/30/14Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to salt-...@googlegroups.com
The current smart file.append adds a newline before the provided content if the
file doesn't end with a newline. Is this really necessary? If someone needs the
newline, I am guessing they will add it to the text they want added.
This behaviour current breaks writing to proc files, because of their response
to fseek.
When i am running:
$ sudo salt-call --local file.append /sys/module/printk/parameters/time 1
...
Traceback (most recent call last):
File "/usr/bin/salt-call", line 11, in <module>
salt_call()
File "/usr/lib/python2.6/site-packages/salt/scripts.py", line
82, in salt_call
client.run()
File "/usr/lib/python2.6/site-packages/salt/cli/__init__.py",
line 314, in run
caller.run()
File "/usr/lib/python2.6/site-packages/salt/cli/caller.py", line
142, in run
ret = self.call()
File "/usr/lib/python2.6/site-packages/salt/cli/caller.py", line
80, in call
ret['return'] = func(*args, **kwargs)
File "/usr/lib/python2.6/site-packages/salt/modules/file.py",
line 1403, in append
ofile.write('{0}\n'.format(line))
IOError: [Errno 22] Invalid argument
What I am expecting is:
$ echo -ne '1\n' | sudo tee /sys/module/printk/parameters/time
1
What is happening is:
$ echo -ne '\n1\n' | sudo tee /sys/module/printk/parameters/time
1
tee: /sys/module/printk/parameters/time: Invalid argument
This is because proc type files behave differently to seek:
>>> f=open("/sys/module/printk/parameters/time","r+")
>>> f.read()
'Y\n'
>>> f.tell()
2
>>> import os
>>> f.seek(-1,os.SEEK_END)
>>> f.tell()
4095
>>> f.read(1)
''
If we have just a dumb open("FNAME","a").write(TEXT) like before, this would
work, like it does in the previous version of this function.
- Sandip