prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  securedrop_init script in Tails doesn't work right if you run it twice
  It appends torrc-additions to torrc multiple times, and it should just append it once.
  
  securedrop_init script in Tails doesn't work right if you run it twice
  It appends torrc-additions to torrc multiple times, and it should just append it once.
  
  
  </issue>
  <code>
  [start of tails_files/securedrop_init.py]
  1 #!/usr/bin/env python
  2 
  3 import os, sys, subprocess
  4 
  5 if __name__ == '__main__':
  6     # check for root
  7     if not os.geteuid()==0:
  8         sys.exit('You need to run this as root')
  9 
  10     # paths
  11     path_torrc_additions = '/home/amnesia/Persistent/.securedrop/torrc_additions'
  12     path_torrc_backup = '/etc/tor/torrc.bak'
  13     path_torrc = '/etc/tor/torrc'
  14 
  15     # load torrc_additions
  16     if os.path.isfile(path_torrc_additions):
  17         torrc_additions = open(path_torrc_additions).read()
  18     else:
  19         sys.exit('Error opening {0} for reading'.format(path_torrc_additions));
  20 
  21     # load torrc
  22     if os.path.isfile(path_torrc_backup):
  23         torrc = open(path_torrc_backup).read()
  24     else:
  25         if os.path.isfile(path_torrc):
  26             torrc = open(path_torrc).read()
  27         else:
  28             sys.exit('Error opening {0} for reading'.format(path_torrc));
  29 
  30         # save a backup
  31         open(path_torrc_backup, 'w').write(torrc)
  32 
  33     # append the additions
  34     open(path_torrc, 'a').write(torrc_additions)
  35 
  36     # reload tor
  37     subprocess.call(['/usr/sbin/service', 'tor', 'reload'])
  38 
  39     # success
  40     subprocess.call(['/usr/bin/sudo', '-u', 'amnesia', '/usr/bin/notify-send', 'Updated torrc', 'You can now connect to your SecureDrop document interface']);
  41 
  42
  [end of tails_files/securedrop_init.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/tails_files/securedrop_init.py b/tails_files/securedrop_init.py
  --- a/tails_files/securedrop_init.py
  +++ b/tails_files/securedrop_init.py
  @@ -31,7 +31,7 @@
           open(path_torrc_backup, 'w').write(torrc)
   
       # append the additions
  -    open(path_torrc, 'a').write(torrc_additions)
  +    open(path_torrc, 'w').write(torrc+torrc_additions)
   
       # reload tor
       subprocess.call(['/usr/sbin/service', 'tor', 'reload'])
  
verification_info: {"golden_diff": "diff --git a/tails_files/securedrop_init.py b/tails_files/securedrop_init.py\n--- a/tails_files/securedrop_init.py\n+++ b/tails_files/securedrop_init.py\n@@ -31,7 +31,7 @@\n         open(path_torrc_backup, 'w').write(torrc)\n \n     # append the additions\n-    open(path_torrc, 'a').write(torrc_additions)\n+    open(path_torrc, 'w').write(torrc+torrc_additions)\n \n     # reload tor\n     subprocess.call(['/usr/sbin/service', 'tor', 'reload'])\n", "issue": "securedrop_init script in Tails doesn't work right if you run it twice\nIt appends torrc-additions to torrc multiple times, and it should just append it once.\n\nsecuredrop_init script in Tails doesn't work right if you run it twice\nIt appends torrc-additions to torrc multiple times, and it should just append it once.\n\n", "before_files": [{"content": "#!/usr/bin/env python\n\nimport os, sys, subprocess\n\nif __name__ == '__main__':\n    # check for root\n    if not os.geteuid()==0:\n        sys.exit('You need to run this as root')\n\n    # paths\n    path_torrc_additions = '/home/amnesia/Persistent/.securedrop/torrc_additions'\n    path_torrc_backup = '/etc/tor/torrc.bak'\n    path_torrc = '/etc/tor/torrc'\n\n    # load torrc_additions\n    if os.path.isfile(path_torrc_additions):\n        torrc_additions = open(path_torrc_additions).read()\n    else:\n        sys.exit('Error opening {0} for reading'.format(path_torrc_additions));\n\n    # load torrc\n    if os.path.isfile(path_torrc_backup):\n        torrc = open(path_torrc_backup).read()\n    else:\n        if os.path.isfile(path_torrc):\n            torrc = open(path_torrc).read()\n        else:\n            sys.exit('Error opening {0} for reading'.format(path_torrc));\n\n        # save a backup\n        open(path_torrc_backup, 'w').write(torrc)\n\n    # append the additions\n    open(path_torrc, 'a').write(torrc_additions)\n\n    # reload tor\n    subprocess.call(['/usr/sbin/service', 'tor', 'reload'])\n\n    # success\n    subprocess.call(['/usr/bin/sudo', '-u', 'amnesia', '/usr/bin/notify-send', 'Updated torrc', 'You can now connect to your SecureDrop document interface']);\n\n", "path": "tails_files/securedrop_init.py"}]}