Blob Blame History Raw
# HG changeset patch
# User Yann Leboulanger <asterix@lagaule.org>
# Date 1334071532 -7200
# Node ID bac8e353d25c7196f2635ef7c2b2e479f6818fab
# Parent  a360737332cd0135df68fb212e6156931ebab312
improve temp file search when using latex to prevent overwriting files

diff --git a/src/common/latex.py b/src/common/latex.py
--- a/src/common/latex.py
+++ b/src/common/latex.py
@@ -59,8 +59,19 @@
 
 def get_tmpfile_name():
     random.seed()
-    int_ = random.randint(0, 100)
-    return os.path.join(gettempdir(), 'gajimtex_' + int_.__str__())
+    while(nb < 100):
+        int_ = random.randint(0, 10000)
+        filename = os.path.join(gettempdir(), 'gajimtex_' + int_.__str__())
+        # Check if a file to not overwrite it
+        ok = True
+        extensions = ['.tex', '.log', '.aux', '.dvi']
+        for ext in extensions:
+            if os.path.exists(filename + ext):
+                ok = False
+                break
+        if ok:
+            return filename
+    return filename
 
 def write_latex(filename, str_):
     texstr = '\\documentclass[12pt]{article}\\usepackage[dvips]{graphicx}'