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

append() does not respect current content if line contains '<' #1294

Closed
ecksun opened this Issue Mar 11, 2015 · 4 comments

Comments

Projects
None yet
4 participants
@ecksun

ecksun commented Mar 11, 2015

I noticed that if I run append() several times with the same content it also appends that line several times, instead of just one time. That is, append() is not idempotent.

If text is already found in filename, the append is not run, and None is returned immediately.

The following small test script can reproduce the issue:

from fabric.contrib.files import append

def run():
      append('testfile', 'some < pipe')

This issue seems to be similar to #341

The error has to do with the '<' symbol.

The problem seems to boil down to the regex that is sent to egrep in contains():
https://github.com/fabric/fabric/blob/master/fabric/contrib/files.py#L360

printing egrep_cmd gives me the following for the above testcase:

egrep "^some\ \<\ pipe$" "$(echo testfile)"

However the correct regex would be:

egrep "^some\ <\ pipe$" "$(echo testfile)"

The incorrect regex seems to be generated by the _escape_for_regex function.

cmattoon pushed a commit to cmattoon/fabric that referenced this issue Apr 13, 2015

cmattoon pushed a commit to cmattoon/fabric that referenced this issue Apr 13, 2015

cmattoon pushed a commit to cmattoon/fabric that referenced this issue Apr 24, 2015

cmattoon pushed a commit to cmattoon/fabric that referenced this issue Apr 24, 2015

@AndreCimander

This comment has been minimized.

AndreCimander commented Aug 9, 2016

+1, still encountering this bug in 1.12, our poor servers are restoring their iptables rules way too many times x)

@hyperknot

This comment has been minimized.

hyperknot commented Jan 26, 2017

I believe I've encountered the same one, with > this time.

This adds multiple lines:

append('/etc/rc.local', 'echo never > /sys/kernel/mm/transparent_hugepage/enabled')
@ecksun

This comment has been minimized.

ecksun commented Jan 26, 2017

I have provided the fix in the initial description, you can probably create a patch from that and submit it. I'm no longer using fabric so will likely not fix this myself :(

@bitprophet

This comment has been minimized.

Member

bitprophet commented Apr 24, 2017

Fixed in #1559!

@bitprophet bitprophet closed this Apr 24, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment