Merge pull request #470 from Emeraude/fix-file-permissions

Fix file permissions
This commit is contained in:
ZeroNet 2016-05-27 12:47:11 +02:00
commit 523a7d4c16
2 changed files with 6 additions and 0 deletions

View File

@ -1,6 +1,7 @@
# Included modules
import os
import sys
import stat
import time
import logging
@ -33,8 +34,10 @@ if not os.path.isdir(config.data_dir):
os.mkdir(config.data_dir)
if not os.path.isfile("%s/sites.json" % config.data_dir):
open("%s/sites.json" % config.data_dir, "w").write("{}")
os.chmod("%s/sites.json" % config.data_dir, stat.S_IRUSR | stat.S_IWUSR)
if not os.path.isfile("%s/users.json" % config.data_dir):
open("%s/users.json" % config.data_dir, "w").write("{}")
os.chmod("%s/users.json" % config.data_dir, stat.S_IRUSR | stat.S_IWUSR)
# Setup logging
if config.action == "main":

View File

@ -1,4 +1,5 @@
import os
import stat
import socket
import struct
import re
@ -10,6 +11,7 @@ import base64
def atomicWrite(dest, content, mode="w"):
try:
permissions = stat.S_IMODE(os.lstat(dest).st_mode)
with open(dest + "-new", mode) as f:
f.write(content)
f.flush()
@ -18,6 +20,7 @@ def atomicWrite(dest, content, mode="w"):
os.rename(dest + "-old", dest + "-old-%s" % time.time())
os.rename(dest, dest + "-old")
os.rename(dest + "-new", dest)
os.chmod(dest, permissions)
os.unlink(dest + "-old")
return True
except Exception, err: