From c9f5bc33f978f5e12669dff0f04082a8967a0a46 Mon Sep 17 00:00:00 2001
From: Walter Purcaro <vuolter@users.noreply.github.com>
Date: Tue, 21 Apr 2015 13:23:53 +0200
Subject: Spare code cosmetics (10)

---
 pyload/database/Backend.py | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

(limited to 'pyload/database/Backend.py')

diff --git a/pyload/database/Backend.py b/pyload/database/Backend.py
index b6540b2be..e851885c0 100644
--- a/pyload/database/Backend.py
+++ b/pyload/database/Backend.py
@@ -175,18 +175,22 @@ class DatabaseBackend(Thread):
                 f.write(str(DB_VERSION))
             return
 
-        with open("files.version", "wb+") as f:
-            v = int(f.read().strip())
-            if v < DB_VERSION:
-                if v < 2:
-                    try:
-                        self.manager.core.log.warning(_("Filedatabase was deleted due to incompatible version."))
-                    except Exception:
-                        print "Filedatabase was deleted due to incompatible version."
-                    remove("files.version")
-                    move("files.db", "files.backup.db")
+        with open("files.version", "rb") as f:
+            v = int(f.read().strip() or 0)
+
+        if v < DB_VERSION:
+            if v < 2:
+                try:
+                    self.manager.core.log.warning(_("Filedatabase was deleted due to incompatible version."))
+                except Exception:
+                    print "Filedatabase was deleted due to incompatible version."
+                remove("files.version")
+                move("files.db", "files.backup.db")
+            
+            with open("files.version", "wb") as f:
                 f.write(str(DB_VERSION))
-                return v
+
+        return v
 
 
     def _convertDB(self, v):
-- 
cgit v1.2.3