Check for invalid directory

main
Bob Mottram 2019-11-29 23:04:37 +00:00
parent aa8956827d
commit 8dc02ae340
5 changed files with 29 additions and 13 deletions

View File

@ -88,8 +88,9 @@ def undoAnnounceCollectionEntry(recentPostsCache: {}, \
nickname=getNicknameFromActor(actor)
cachedPostFilename= \
getCachedPostFilename(baseDir,nickname,domain,postJsonObject)
if os.path.isfile(cachedPostFilename):
os.remove(cachedPostFilename)
if cachedPostFilename:
if os.path.isfile(cachedPostFilename):
os.remove(cachedPostFilename)
removePostFromCache(postJsonObject,recentPostsCache)
if not postJsonObject.get('type'):
@ -144,8 +145,9 @@ def updateAnnounceCollection(recentPostsCache: {}, \
nickname=getNicknameFromActor(actor)
cachedPostFilename= \
getCachedPostFilename(baseDir,nickname,domain,postJsonObject)
if os.path.isfile(cachedPostFilename):
os.remove(cachedPostFilename)
if cachedPostFilename:
if os.path.isfile(cachedPostFilename):
os.remove(cachedPostFilename)
removePostFromCache(postJsonObject,recentPostsCache)
if not postJsonObject.get('object'):

View File

@ -37,8 +37,9 @@ def undoBookmarksCollectionEntry(recentPostsCache: {}, \
nickname=getNicknameFromActor(actor)
cachedPostFilename= \
getCachedPostFilename(baseDir,nickname,domain,postJsonObject)
if os.path.isfile(cachedPostFilename):
os.remove(cachedPostFilename)
if cachedPostFilename:
if os.path.isfile(cachedPostFilename):
os.remove(cachedPostFilename)
removePostFromCache(postJsonObject,recentPostsCache)
if not postJsonObject.get('type'):
@ -143,8 +144,9 @@ def updateBookmarksCollection(recentPostsCache: {}, \
nickname=getNicknameFromActor(actor)
cachedPostFilename= \
getCachedPostFilename(baseDir,nickname,domain,postJsonObject)
if os.path.isfile(cachedPostFilename):
os.remove(cachedPostFilename)
if cachedPostFilename:
if os.path.isfile(cachedPostFilename):
os.remove(cachedPostFilename)
removePostFromCache(postJsonObject,recentPostsCache)
if not postJsonObject.get('object'):

10
like.py
View File

@ -35,8 +35,9 @@ def undoLikesCollectionEntry(recentPostsCache: {}, \
nickname=getNicknameFromActor(actor)
cachedPostFilename= \
getCachedPostFilename(baseDir,nickname,domain,postJsonObject)
if os.path.isfile(cachedPostFilename):
os.remove(cachedPostFilename)
if cachedPostFilename:
if os.path.isfile(cachedPostFilename):
os.remove(cachedPostFilename)
removePostFromCache(postJsonObject,recentPostsCache)
if not postJsonObject.get('type'):
@ -117,8 +118,9 @@ def updateLikesCollection(recentPostsCache: {}, \
nickname=getNicknameFromActor(actor)
cachedPostFilename= \
getCachedPostFilename(baseDir,nickname,domain,postJsonObject)
if os.path.isfile(cachedPostFilename):
os.remove(cachedPostFilename)
if cachedPostFilename:
if os.path.isfile(cachedPostFilename):
os.remove(cachedPostFilename)
removePostFromCache(postJsonObject,recentPostsCache)
if not postJsonObject.get('object'):

View File

@ -447,8 +447,15 @@ def getCachedPostFilename(baseDir: str,nickname: str,domain: str, \
postJsonObject: {}) -> str:
"""Returns the html cache filename for the given post
"""
cachedPostDir=getCachedPostDirectory(baseDir,nickname,domain)
if not os.path.isdir(cachedPostDir):
print('ERROR: invalid html cache directory '+cachedPostDir)
return None
if '@' not in cachedPostDir:
print('ERROR: invalid html cache directory '+cachedPostDir)
return None
cachedPostFilename= \
getCachedPostDirectory(baseDir,nickname,domain)+ \
cachedPostDir+ \
'/'+postJsonObject['id'].replace('/activity','')
print('CACHE: 1 '+nickname+' '+domain+' '+cachedPostFilename)
if '#' in cachedPostFilename:

View File

@ -1948,6 +1948,9 @@ def loadIndividualPostAsHtmlFromCache(baseDir: str,nickname: str,domain: str, \
cachedPostFilename=getCachedPostFilename(baseDir,nickname,domain,postJsonObject)
postHtml=''
if not cachedPostFilename:
return postHtml
if not os.path.isfile(cachedPostFilename):
return postHtml