Skip to content

Commit

Permalink
Do not create duplicate lines when calling append(..., use_sudo=True)
Browse files Browse the repository at this point in the history
This happened on a file unreadable by an unprivileged user, for
example /root/.ssh/authorized_keys when use_sudo was True.

This fix passes along use_sudo to exists, so it can check if the file
*really* exists before appending to it.

Fixes issue fabric#341.
  • Loading branch information
Martin Vilcans committed Aug 30, 2011
1 parent aa4551c commit e082193
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion fabric/contrib/files.py
Expand Up @@ -321,7 +321,7 @@ def append(filename, text, use_sudo=False, partial=False, escape=True):
text = [text]
for line in text:
regex = '^' + re.escape(line) + ('' if partial else '$')
if (exists(filename) and line
if (exists(filename, use_sudo=use_sudo) and line
and contains(filename, regex, use_sudo=use_sudo)):
continue
line = line.replace("'", r'\'') if escape else line
Expand Down

0 comments on commit e082193

Please sign in to comment.