Rev414, Atomic save for sites.json and users.json
This commit is contained in:
parent
917393c022
commit
6ae0c1a626
4 changed files with 12 additions and 5 deletions
|
@ -8,7 +8,7 @@ class Config(object):
|
|||
|
||||
def __init__(self, argv):
|
||||
self.version = "0.3.2"
|
||||
self.rev = 409
|
||||
self.rev = 414
|
||||
self.argv = argv
|
||||
self.action = None
|
||||
self.createParser()
|
||||
|
|
|
@ -25,6 +25,7 @@ from Debug import Debug
|
|||
from Content import ContentManager
|
||||
from SiteStorage import SiteStorage
|
||||
from Crypt import CryptHash
|
||||
from util import utils
|
||||
import SiteManager
|
||||
|
||||
|
||||
|
@ -88,8 +89,7 @@ class Site:
|
|||
def saveSettings(self):
|
||||
sites_settings = json.load(open("%s/sites.json" % config.data_dir))
|
||||
sites_settings[self.address] = self.settings
|
||||
open("%s/sites.json" % config.data_dir, "w").write(json.dumps(sites_settings, indent=2, sort_keys=True))
|
||||
return
|
||||
utils.atomicWrite("%s/sites.json" % config.data_dir, json.dumps(sites_settings, indent=2, sort_keys=True))
|
||||
|
||||
# Max site size in MB
|
||||
def getSizeLimit(self):
|
||||
|
|
|
@ -5,7 +5,7 @@ import time
|
|||
from Crypt import CryptBitcoin
|
||||
from Plugin import PluginManager
|
||||
from Config import config
|
||||
|
||||
from util import utils
|
||||
|
||||
@PluginManager.acceptPlugins
|
||||
class User(object):
|
||||
|
@ -35,7 +35,7 @@ class User(object):
|
|||
user_data["master_seed"] = self.master_seed
|
||||
user_data["sites"] = self.sites
|
||||
user_data["certs"] = self.certs
|
||||
open("%s/users.json" % config.data_dir, "w").write(json.dumps(users, indent=2, sort_keys=True))
|
||||
utils.atomicWrite("%s/users.json" % config.data_dir, json.dumps(users, indent=2, sort_keys=True))
|
||||
self.log.debug("Saved")
|
||||
|
||||
def getAddressAuthIndex(self, address):
|
||||
|
|
7
src/util/utils.py
Normal file
7
src/util/utils.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
import os
|
||||
|
||||
def atomicWrite(dest, content, mode="w"):
|
||||
open(dest+"-new", mode).write(content)
|
||||
os.rename(dest, dest+"-old")
|
||||
os.rename(dest+"-new", dest)
|
||||
os.unlink(dest+"-old")
|
Loading…
Reference in a new issue