Add exception handling for index

main2
Bob Mottram 2019-10-20 13:43:59 +01:00
parent 5c67ada3bb
commit 53fc839cae
2 changed files with 16 additions and 13 deletions

View File

@ -1516,16 +1516,22 @@ def inboxUpdateIndex(baseDir: str,handle: str,destinationFilename: str,debug: bo
if '/'+boxname+'/' in destinationFilename:
destinationFilename=destinationFilename.split('/'+boxname+'/')[1]
if os.path.isfile(indexFilename):
try:
with open(indexFilename, 'r+') as indexFile:
content = indexFile.read()
indexFile.seek(0, 0)
indexFile.write(destinationFilename+'\n'+content)
return True
except Exception as e:
print('Failed to write entry to index '+str(e))
else:
try:
indexFile=open(indexFilename,'w+')
if indexFile:
indexFile.write(destinationFilename+'\n')
indexFile.close()
except Exception as e:
print('Failed to write initial entry to index '+str(e))
return False

View File

@ -2040,10 +2040,7 @@ def createBoxBase(session,baseDir: str,boxname: str, \
maxPostCtr=(itemsPerPage+3)*pageNumber
with open(indexFilename, 'r') as indexFile:
for postFilename in indexFile:
statusNumber=getStatusNumberFromPostFilename(postFilename)
if not statusNumber:
continue
postsInBox[statusNumber]=os.path.join(boxDir, postFilename.replace('\n',''))
postsInBox[postsCtr]=os.path.join(boxDir, postFilename.replace('\n',''))
postsCtr+=1
if maxPostCtr:
if postsCtr>=maxPostCtr: