Commit c9d88965 authored by David Johnson's avatar David Johnson

Fix bugs with database file handling.

parent 86cd96d1
Pipeline #3008 passed with stages
in 14 seconds
...@@ -279,8 +279,13 @@ class NlSdnConfig(ConfigSection): ...@@ -279,8 +279,13 @@ class NlSdnConfig(ConfigSection):
self.dbfile = jsonblob["dbfile"] self.dbfile = jsonblob["dbfile"]
else: else:
self.dbfile = "/var/lib/nlsdn/db.json" self.dbfile = "/var/lib/nlsdn/db.json"
if not os.access(self.dbfile,os.W_OK | os.R_OK): if os.path.exists(self.dbfile) \
and not os.access(self.dbfile,os.W_OK | os.R_OK):
raise ConfigError( raise ConfigError(
"cannot read/write nlsdn dbfile '%s'" % (self.dbfile,)) "cannot read/write nlsdn dbfile '%s'" % (self.dbfile,))
elif not os.path.exists(os.path.dirname(self.dbfile)) \
or not os.access(os.path.dirname(self.dbfile),os.W_OK | os.R_OK):
raise ConfigError(
"cannot read/write nlsdn dbfile dir '%s'" % (os.path.dirname(self.dbfile),))
pass pass
pass pass
import os
import sys import sys
import json import json
from nlsdn.util import CustomJsonEncoder from nlsdn.util import CustomJsonEncoder
...@@ -232,15 +233,16 @@ class Engine(object): ...@@ -232,15 +233,16 @@ class Engine(object):
def load(self,force=False,ensure=True): def load(self,force=False,ensure=True):
if self._loaded and not force: if self._loaded and not force:
return return
fd = file(self.path,'r')
raw = "" raw = ""
while True: if os.path.exists(self.path):
x = fd.read() fd = file(self.path,'r')
if not x: while True:
break x = fd.read()
raw += x if not x:
fd.close() break
raw += x
fd.close()
rdb = {} rdb = {}
if raw != "": if raw != "":
rdb = json.loads(raw) rdb = json.loads(raw)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment