home · contact · privacy
Fix bug occuring when trying to append to non-existant file.
[url-catcher] / url_catcher.py
old mode 100644 (file)
new mode 100755 (executable)
index ac4b7a7..0121896
@@ -1,3 +1,5 @@
+#!/usr/bin/python3
+
 import bottle
 import validators
 import html
@@ -47,7 +49,7 @@ os.makedirs(lists_dir, exist_ok=True)
 def atomic_write(path, content, mode):
     """Atomic write/append to file."""
     _, tmpPath = tempfile.mkstemp()
-    if 'a' == mode:
+    if 'a' == mode and os.path.exists(path):
         shutil.copy2(path, tmpPath)
     f = open(tmpPath, mode)
     f.write(content)