Fix Unhandled File Access Errors
This commit is contained in:
parent
b29884db78
commit
f9d7ccd83c
1 changed files with 12 additions and 4 deletions
|
@ -255,12 +255,16 @@ class SiteStorage(object):
|
||||||
if create_dirs:
|
if create_dirs:
|
||||||
file_inner_dir = os.path.dirname(inner_path)
|
file_inner_dir = os.path.dirname(inner_path)
|
||||||
self.ensureDir(file_inner_dir)
|
self.ensureDir(file_inner_dir)
|
||||||
|
try :
|
||||||
return open(file_path, mode, **kwargs)
|
return open(file_path, mode, **kwargs)
|
||||||
|
except IOError as err:
|
||||||
|
self.log.error("File Access error: %s" % Debug.formatException(err))
|
||||||
|
return None
|
||||||
|
|
||||||
# Open file object
|
# Open file object
|
||||||
@thread_pool_fs_read.wrap
|
@thread_pool_fs_read.wrap
|
||||||
def read(self, inner_path, mode="rb"):
|
def read(self, inner_path, mode="rb"):
|
||||||
return open(self.getPath(inner_path), mode).read()
|
return self.open(inner_path, mode).read()
|
||||||
|
|
||||||
@thread_pool_fs_write.wrap
|
@thread_pool_fs_write.wrap
|
||||||
def writeThread(self, inner_path, content):
|
def writeThread(self, inner_path, content):
|
||||||
|
@ -369,8 +373,12 @@ class SiteStorage(object):
|
||||||
# Load and parse json file
|
# Load and parse json file
|
||||||
@thread_pool_fs_read.wrap
|
@thread_pool_fs_read.wrap
|
||||||
def loadJson(self, inner_path):
|
def loadJson(self, inner_path):
|
||||||
|
try:
|
||||||
with self.open(inner_path, "r", encoding="utf8") as file:
|
with self.open(inner_path, "r", encoding="utf8") as file:
|
||||||
return json.load(file)
|
return json.load(file)
|
||||||
|
except Exception as err:
|
||||||
|
self.log.error("Json load error: %s" % Debug.formatException(err))
|
||||||
|
return None
|
||||||
|
|
||||||
# Write formatted json file
|
# Write formatted json file
|
||||||
def writeJson(self, inner_path, data):
|
def writeJson(self, inner_path, data):
|
||||||
|
|
Loading…
Reference in a new issue