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: if '/'+boxname+'/' in destinationFilename:
destinationFilename=destinationFilename.split('/'+boxname+'/')[1] destinationFilename=destinationFilename.split('/'+boxname+'/')[1]
if os.path.isfile(indexFilename): if os.path.isfile(indexFilename):
with open(indexFilename, 'r+') as indexFile: try:
content = indexFile.read() with open(indexFilename, 'r+') as indexFile:
indexFile.seek(0, 0) content = indexFile.read()
indexFile.write(destinationFilename+'\n'+content) indexFile.seek(0, 0)
return True indexFile.write(destinationFilename+'\n'+content)
return True
except Exception as e:
print('Failed to write entry to index '+str(e))
else: else:
indexFile=open(indexFilename,'w+') try:
if indexFile: indexFile=open(indexFilename,'w+')
indexFile.write(destinationFilename+'\n') if indexFile:
indexFile.close() indexFile.write(destinationFilename+'\n')
indexFile.close()
except Exception as e:
print('Failed to write initial entry to index '+str(e))
return False return False

View File

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