Rev546, Sidebar drag fix, Fix rebuild on dbschema changes, Test Dbschema changes, Fix atomicWrite error when old file already exists

This commit is contained in:
HelloZeroNet 2015-11-05 23:19:36 +01:00
parent bd67d8fe14
commit c2fc131cdc
9 changed files with 31 additions and 8 deletions

View file

@ -8,7 +8,7 @@ class Config(object):
def __init__(self, argv):
self.version = "0.3.2"
self.rev = 542
self.rev = 546
self.argv = argv
self.action = None
self.createParser()

View file

@ -96,7 +96,7 @@ class Peer(object):
self.onConnectionError()
return None # Connection failed
for retry in range(0, 3): # Retry 3 times
for retry in range(1, 4): # Retry 3 times
try:
res = self.connection.request(cmd, params, stream_to)
if not res:

View file

@ -45,7 +45,7 @@ class SiteStorage:
if check and not self.db_checked:
changed_tables = self.db.checkTables()
if changed_tables:
self.rebuildDb(delete_db=False) # Todo only update the changed table datas
self.rebuildDb(delete_db=False) # TODO: only update the changed table datas
def closeDb(self):
if self.db:
@ -176,7 +176,9 @@ class SiteStorage:
# Update Sql cache
if inner_path == "dbschema.json":
self.has_db = self.isFile("dbschema.json")
self.getDb().checkTables() # Check if any if table schema changed
# Reopen DB to check changes
self.closeDb()
self.openDb()
elif inner_path.endswith(".json") and self.has_db: # Load json file to db
self.log.debug("Loading json file to db: %s" % inner_path)
try:

View file

@ -49,6 +49,21 @@ class TestDb:
assert "test_id" in cols
assert "title" in cols
# Add new table
assert "newtest" not in tables
db.schema["tables"]["newtest"] = {
"cols": [
["newtest_id", "INTEGER"],
["newtitle", "TEXT"],
],
"indexes": ["CREATE UNIQUE INDEX newtest_id ON newtest(newtest_id)"],
"schema_changed": 1426195822
}
db.checkTables()
tables = [row["name"] for row in db.execute("SELECT name FROM sqlite_master WHERE type='table'")]
assert "test" in tables
assert "newtest" in tables
db.close()
# Cleanup

View file

@ -3,6 +3,7 @@ import socket
import struct
import re
import collections
import time
def atomicWrite(dest, content, mode="w"):
@ -10,6 +11,8 @@ def atomicWrite(dest, content, mode="w"):
f.write(content)
f.flush()
os.fsync(f.fileno())
if os.path.isfile(dest + "-old"): # Previous incomplete write
os.rename(dest + "-old", dest + "-old-%s" % time.time())
os.rename(dest, dest + "-old")
os.rename(dest + "-new", dest)
os.unlink(dest + "-old")