Skip to content

Commit

Permalink
Merge pull request HelloZeroNet#470 from Emeraude/fix-file-permissions
Browse files Browse the repository at this point in the history
Fix file permissions
  • Loading branch information
HelloZeroNet committed May 27, 2016
2 parents 81f1966 + 9e9832a commit 523a7d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Included modules
import os
import sys
import stat
import time
import logging

Expand Down Expand Up @@ -33,8 +34,10 @@
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":
Expand Down
3 changes: 3 additions & 0 deletions src/util/helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import stat
import socket
import struct
import re
Expand All @@ -10,6 +11,7 @@

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()
Expand All @@ -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:
Expand Down

0 comments on commit 523a7d4

Please sign in to comment.